简体   繁体   English

如何在单个Elasticsearch查询中查询多个方面

[英]How to query for many facets in single elasticsearch query

I'm looking for a way to query the distribution of the top n values for many object fields in single query 我正在寻找一种方法来查询单个查询中许多对象字段的前n个值的分布

My object in elastic search looks like: 我在弹性搜索中的对象看起来像:

obj: {
  os: "Android",
  device_model: "Samsung Galaxy S II (GT-I9100)",
  device_brand: "Samsung",
  os_version: "Android-2.3",
  country: "BR",
  interests: [1,2,3],
  behavioral_segment: ["sport", "lifestyle"]

}

The following query brings the distribution of the values for specific field with number of appearances of this value only for the UK users 以下查询将仅针对英国用户的特定字段的值分布与该值的出现次数一起显示

  curl -XPOST http://<endpoint>/profiles/_search?search_type=count -d '
{
  "query": {
      "match": {
        "country" : "UK"  
    }
 },
 "facets": {
    "ItemsPerCategoryCount": {
      "terms": {
          "field": "behavioral_segment"
      }
  }
  }
}'

How can I query for many fields - for example I would like to get a result for behavioral_segment and device_brand and os in single query. 如何查询许多字段-例如,我想在单个查询中获得behavioral_segment和device_brand和os的结果。 Is it possible? 可能吗?

In the facets section of the query, you should use the fields parameter. 在查询的方面部分,应使用fields参数。

"facets": {
  "ItemsPerCategoryCount": {
    "terms": {
      "fields": ["behavioral_segment","device_brand"]
    }
  }
}

That should solve your problem, but of course it might not garantee the coherence of the data 那应该可以解决您的问题,但是当然可能不会保证数据的一致性

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

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