[英]Elasticsearch query array field
I used elastic search in my project. 我在项目中使用了弹性搜索。 I stored some values to ES.
我将一些值存储到ES。 I want to query the array field from elastic search.
我想从弹性搜索查询数组字段。 I have to get how many time the array of value came.
我必须弄清楚价值阵列来了多少次。 For example, You could see the below code, In that, image and price are coming two times.
例如,您可能会看到以下代码,其中,图像和价格将出现两次。
{
"missing_fields_arr": ["images", "price"]
},
{
"missing_fields_arr": ["price"]
},
{
"missing_fields_arr": ["images"]
},
{
"missing_fields_arr": ["images", "price"]
}
and I expected output should be 我预计输出应该是
"aggregations": {
"missing_fields": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "images, price",
"doc_count": 2
},
{
"key": "price",
"doc_count": 1
},
{
"key": "images",
"doc_count": 1
}
]
}
}
My code is here, 我的代码在这里,
{
"query":{
"bool":{
"must":[
{
"range": {
"@timestamp":{
"gte": "2017-07-20T00:00:00.000Z",
"lte": "2017-07-28T23:59:59.999Z"
}
}
},
{
"term": {
"tracker_name": true
}
}
]
}
},
"from": 0,
"size": 0,
"aggregations" : {
"missing_fields": {"terms": {"field": "missing_fields_arr.raw", "size": 0} }
}
}
You need to use the count api it's much more efficient than the search: of course combined with a little bit of regex ex : 您需要使用count api,它比搜索要有效得多:当然要结合一点regex ex:
curl -XGET 'localhost:9200/product/item/_count?pretty' -H 'Content-Type:application/json' -d'\
{ "query" : { "term" : { "image|price" } } } '
GET /product/item/_count
{
"query" : {
"term" : { "image|price"}
}
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-count.html https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/search-count.html https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics -valuecount-aggregation.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.