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

 

posted on 2022-04-25 11:52  MaXianZhe  阅读(6620)  评论(0编辑  收藏  举报

导航