简体   繁体   English

Elasticsearch 查询具有多个条件的不同值

[英]Elasticsearch query for distinct values with multiple conditions

I want to perform following in the elasticsearch.我想在 elasticsearch 中执行以下操作。

select distinct name, city from students where class = 10 and age = 15; select 不同的名字,城市来自学生,其中 class = 10 和年龄 = 15;

and it should return all distinct values for name and city.它应该返回名称和城市的所有不同值。 How to perform this?如何执行此操作?

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-collapse . https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-collapse Field collapsing Should be helpful here.字段折叠在这里应该会有所帮助。

{
    "query": { 
    "bool": {
     "must": [
       {"match": 
         {
         "class": 10
         }
       },
       {"match": 
         {
         "age": 15
         }
       }
     ] 
    }
  },
    "collapse" : {
        "field" : "name.keyword" ,
        "inner_hits" : {
          "name": "by_type",
            "collapse" : {"field" : "city.keyword"}
        }
    }, 
    "size": 100
}

The above query will return one document par name and city after matching with class and age.上述查询在匹配 class 和年龄后,将返回一个文档名称和城市。

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

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