关于包含 json 用于 bool 查询的 elasticsearch 文档的混淆

confusion about elasticsearch documentation about containing json for bool query

在这个 link 的 bool 查询的 elasticsearch 文档中: https://www.elastic.co/guide/en/elasticsearch/reference/1.4/query-dsl-bool-query.html

它没有说包含结构。如果我只是按照他们的方式使用 bool,那是完全错误的。我需要用 query/filter/ 过滤查询的一些愚蠢组合来包围它。我不确定在弹性中形成 json 查询的正确方法是什么。这些文件在很多地方关于什么去哪里以及如何去似乎是完全矛盾的。那里有知道如何正确形成查询的 elasticsearch 专家吗?

首先,有一个 "bool" 查询和一个 "bool" 过滤器,它们位于不同的地方,做的事情略有不同。作为一般规则,如果您可以使用过滤器(其中许多可以缓存,即使不缓存也快一点)。如果你需要 "match" 那么你需要一个查询。

您引用的页面上的示例实际上可以任意使用:

作为查询:

POST /test_index/_search
{
   "query": {
      "bool": {
         "must": {
            "term": {
               "user": "kimchy"
            }
         },
         "must_not": {
            "range": {
               "age": {
                  "from": 10,
                  "to": 20
               }
            }
         },
         "should": [
            {
               "term": {
                  "tag": "wow"
               }
            },
            {
               "term": {
                  "tag": "elasticsearch"
               }
            }
         ],
         "minimum_should_match": 1,
         "boost": 1
      }
   }
}

或作为过滤器(在 filtered query 中):

POST /test_index/_search
{
   "query": {
      "filtered": {
         "filter": {
            "bool": {
               "must": {
                  "term": {
                     "user": "kimchy"
                  }
               },
               "must_not": {
                  "range": {
                     "age": {
                        "from": 10,
                        "to": 20
                     }
                  }
               },
               "should": [
                  {
                     "term": {
                        "tag": "wow"
                     }
                  },
                  {
                     "term": {
                        "tag": "elasticsearch"
                     }
                  }
               ],
               "minimum_should_match": 1
            }
         }
      }
   }
}

此外,我对 ES 文档完全感到沮丧。我已经和他们一起工作了几年,他们似乎并没有变得更好。也许负责文档的人并不那么在意。阴谋论观点认为,糟糕的文件有助于公司销售专业服务。