Elasticsearch查询数组字段

时间:2017-07-31 08:38:01

标签: elasticsearch kibana kibana-5

我在项目中使用了弹性搜索。我将一些值存储到ES。我想从弹性搜索中查询数组字段。我必须得到价值数组的时间。例如,您可以看到以下代码,其中,图像和价格将会出现两次。

$line[$k][1]

我希望输出

{
 "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
            }
        ]
    }
}

1 个答案:

答案 0 :(得分:1)

你需要使用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"}
    }
}

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