<p><strong>airza</strong>他用CURL格式给出的关于过滤器的答案一针见血。我怀疑您所看到的问题很大程度上是由于使用了抽象模块,如<code>elasticutils</code>-首先熟悉底层的ES查询协议是很好的。这将使理解<code>elasticutils</code>更容易。正如我在上面的评论中所说,我建议安装'Sense',一个googlechrome的插件,可以让你轻松地查询你的ES集群:<a href="https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo?hl=en" rel="nofollow">https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo?hl=en</a>。在</p>
<p>Elasticsearch查询过滤器非常灵活,而且是可嵌套的。您可以很容易地将<code>or</code>过滤器嵌套在<code>bool</code><code>must</code>过滤器中。示例:</p>
<pre><code>{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"or": [
{"exists": {"field": "sessions"}},
{"range": {"id": {"gte": 56000}}}
]
},
{
"term": {"age_min": "13"}
}
],
"should": [
{
"term": {"area": "1"}
}
]
}
}
}
}
}
</code></pre>
<p>在本例中,结果必须与两个<code>must</code><code>or</code>过滤器和<code>age_min</code><code>term</code>过滤器中的一个匹配,并且<code>should</code>子句中与<code>area</code><code>term</code>过滤器匹配的项目的排名将高于不匹配的项目。在</p>