elasticsearch,Filter,elasticsearch" /> elasticsearch,Filter,elasticsearch" />

Filter elasticsearch中的术语和范围筛选器无法工作

Filter elasticsearch中的术语和范围筛选器无法工作,filter,elasticsearch,Filter,elasticsearch,我有记录 浏览人数:300000000 作者:psy 但是我找不到这张唱片 如何修复我的代码 { "query":{ "filtered" :{ "filter" :{ "and":[{"term" :{"author": "psy"}}, {"range" :{"viewCount" :{ "gte" : 3000000 }}}] }, "query":{ "multi_match" : { "quer

我有记录

浏览人数:300000000 作者:psy

但是我找不到这张唱片

如何修复我的代码

{ "query":{
 "filtered" :{
     "filter" :{ 
        "and":[{"term" :{"author": "psy"}},
               {"range" :{"viewCount" :{ "gte" : 3000000 }}}] },
      "query":{ 
         "multi_match" : { "query" : "psy", "fields" : ["title","content"] } } } },
               "size": 20 }

很难从您发布的内容中确定,但问题似乎出在您发布的代码的查询部分。当我保存您发布的文档(至少是我认为您的意思)并运行搜索查询时,它没有返回。但是当我删除了查询部分并运行了过滤部分时,文档被返回了。更准确地说,我创建了一个索引并添加了文档:

DELETE /test_index

PUT /test_index

PUT /test_index/doc/1
{
   "viewCount": 300000000,
   "author": "psy"
}
然后运行筛选的查询:

POST /test_index/_search
{
   "query": {
      "filtered": {
         "filter": {
            "and": [
               {
                  "term": {
                     "author": "psy"
                  }
               },
               {
                  "range": {
                     "viewCount": {
                        "gte": 3000000
                     }
                  }
               }
            ]
         },
         "query": {
            "multi_match": {
               "query": "psy",
               "fields": [
                  "title",
                  "content"
               ]
            }
         }
      }
   },
   "size": 20
}
...
{
   "took": 2,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 0,
      "max_score": null,
      "hits": []
   }
}
什么都没有。当我只运行查询部分时:

我也一无所获。但当我只运行过滤器部分时:

文件被退回。所以这里有点不对劲:

"query": {
    "multi_match": {
       "query": "psy",
       "fields": [
          "title",
          "content"
       ]
    }
}
由于我拥有的文档不包含这些字段,因此它与查询不匹配,因此不会返回。也许您的文档中有这些字段,但是如果没有更多关于您的设置的信息,就很难告诉您出了什么问题。如果您发布映射和一些示例文档,可能会有所帮助

POST /test_index/_search
{
   "filter": {
      "and": [
         {
            "term": {
               "author": "psy"
            }
         },
         {
            "range": {
               "viewCount": {
                  "gte": 3000000
               }
            }
         }
      ]
   }
}
...
{
   "took": 2,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "test_index",
            "_type": "doc",
            "_id": "1",
            "_score": 1,
            "_source": {
               "viewCount": 300000000,
               "author": "psy"
            }
         }
      ]
   }
}
"query": {
    "multi_match": {
       "query": "psy",
       "fields": [
          "title",
          "content"
       ]
    }
}