[英]Elasticsearch query array field
我在项目中使用了弹性搜索。 我将一些值存储到ES。 我想从弹性搜索查询数组字段。 我必须弄清楚价值阵列来了多少次。 例如,您可能会看到以下代码,其中,图像和价格将出现两次。
{
"missing_fields_arr": ["images", "price"]
},
{
"missing_fields_arr": ["price"]
},
{
"missing_fields_arr": ["images"]
},
{
"missing_fields_arr": ["images", "price"]
}
我预计输出应该是
"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
}
]
}
}
我的代码在这里,
{
"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} }
}
}
您需要使用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/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.