如何过滤Elasticsearch结果中的数组?

时间:2019-04-30 11:46:56

标签: node.js elasticsearch

我想过滤ES在数组内给出的结果。我们可以说文档包含随机数据数组。是否可以在该数组中显示具有特定结果的文档?

这是我的查询

GET /products/_search
{
  "query": {
    "bool"  : {
      "must" : [
        { "match_phrase" :{ "shop": "shop_url" }},
        {"match_phrase"  :{"id" : "000111222" }}
      ]
    }
 },
  "_source": ["title","audiences"]
}

结果看起来很正常

{
        "_source" : {
          "audiences" : [
            {
              "store_id" : "19",
              "account_id" : 115,
              "fb_id" : 111111,
              "name" : "name it ",
              "rule" : "{}",
              "source_id" : 111111,
              "type" : "TYPE IT"
            },
            {
              "store_id" : "19",
              "account_id" : 114,
              "fb_id" : 222222,
              "name" : "name it ",
              "rule" : "{}",
              "source_id" : 22222,
              "type" : "TYPE IT"
            }

          ],
          "title" : "title here"
        }
      } 
我正在寻找的

结果。 (按数组内的字段过滤)

{
        "_index" : "products",
        "_type" : "_doc",
        "_id" : "744376893505",
        "_score" : 1.0006012,
        "_source" : {
          "audiences" : [
            {
              "store_id" : "19",
              "account_id" : 115,
              "fb_id" : 111111,
              "name" : "name it ",
              "rule" : "{}",
              "source_id" : 111111,
              "type" : "TYPE IT"
            }
          ],
          "title" : "title here"
        }
      }

0 个答案:

没有答案