其他分享
首页 > 其他分享> > ES如何查询数组类型字段

ES如何查询数组类型字段

作者:互联网

假设当前有数据

{
        "_index" : "document_index",
        "_type" : "_doc",
        "_id" : "documentId-001",
        "_score" : 1.0,
        "_source" : {
          "_class" : "com.chinaunicom.base.server.documentsearch.entity.DocumentSearch",
          "document_id" : "documentId-001",
          "title" : "title-001",
          "teams" : [
            "AA",
            "BB",
            "CC"
          ]
        }
      },

有两种查询

GET document_index/_search  数组中同时有两个值,所以该语句查不到记录返回
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "teams": "AA"
          }
        },
        {
          "term": {
            "teams": "DD"
          }
        }
      ]
    }
  }
}

GET document_index/_search  数组中值或关系,只要有AA或者DD,就可以返回
{
  "query": {
    "bool": {
      "filter": [
        {
          "terms": {
            "teams": [
              "AA",
              "DD"
            ]
          }
        }
      ]
    }
  }
}

 

标签:AA,index,查询,DD,teams,001,数组,document,ES
来源: https://www.cnblogs.com/juniorMa/p/16189600.html