简体   繁体   English

使用过滤器进行弹性搜索搜索查询

[英]Elastic search search query with Filter

Am new to elastic search, this is my query to find a exact match in my collection. 这是弹性搜索的新手,这是我在集合中查找完全匹配的查询。

{
   "query": {
      "filtered": {
         "query": {
            "match": {
               "_id": {
                  "query": "1"
               }
            }
         },      
       "filter": {
                "term" : {
                    "team_id":"2",
                    "created_user":"099"
                }
            }     
   }
   }
}

By running this query I am getting one record, but my problem is its not matching "team_id" filed. 通过运行此查询,我得到了一条记录,但是我的问题是它与“ team_id”字段不匹配。 When I change team_id to some other value eg: 4, I am still getting the record with team_id = 2, Please help me to write an elastic search query with three fields. 当我将team_id更改为其他值时,例如:4,我仍在获取team_id = 2的记录,请帮助我编写一个包含三个字段的弹性搜索查询。 Thanks 谢谢

If you want exact match, be sure that fields that you want to make search operation must be not_analyzed . 如果要精确匹配,请确保要进行搜索操作的字段必须not_analyzed And it seems you are using multiple case in your filter. 看来您在过滤器中使用了多种情况。 You can refactor your query by using and filter like; 您可以使用和过滤类似来重构查询;

{
   "query": {
      "filtered": {
         "query": {
            "match": {
               "_id": {
                  "query": "1"  // remember that, this will always return one result. Update here according to your needs. For example, use tag instead of _id like tag=responsive in order to get results that matches tag field with responsive
               }
            }
         },      
       "filter": {
            "and": [
                {
                  "term": {"team_id":"2"}
                },
                {
                  "term": {"created_user":"099"}
                }
            ]
        }     
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM