elasticsearch Elasticsearch查询数组字段
我在我的项目中使用了弹性搜索。我将一些值存储到ES。我想从弹性搜索中查询数组字段。我必须得到值数组出现的时间。例如,您可以看到下面的代码,其中,image和price出现了两次elasticsearch Elasticsearch查询数组字段,elasticsearch,kibana,kibana-5,elasticsearch,Kibana,Kibana 5,我在我的项目中使用了弹性搜索。我将一些值存储到ES。我想从弹性搜索中查询数组字段。我必须得到值数组出现的时间。例如,您可以看到下面的代码,其中,image和price出现了两次 { "missing_fields_arr": ["images", "price"] }, { "missing_fields_arr": ["price"] }, { "missing_fields_arr": ["images"] }, { "missing_fields_arr": ["images",
{
"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,它比搜索更高效: 当然,再加上一点正则表达式 例:
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"}
}
}