elasticsearch nested 对象

创建测试数据

DELETE student
# 创建 Nested 对象 Mapping
PUT student
{
      "mappings" : {
      "properties" : {
        "name" : {
          "type": "nested",
          "properties" : {
            "first_name" : {"type" : "keyword"},
            "last_name" : {"type" : "keyword"}
          }},
        "commet" : {
          "type" : "text",
          "fields" : {"keyword":{"type":"keyword","ignore_above":256}}
        }
      }
    }
}
POST student/_doc/1
{
  "commet":"good",
  "name":[
    {
      "first_name":"wang ",
      "last_name":"er"
    },

    {
      "first_name":"zhang",
      "last_name":"san"
    }

  ]
}

 Nested 查询 ,hit 为0 ,表示正确

POST student/_search
{
  "query": {
    "bool": {
      "must": [
        {"match": {"commet": "good"}},
        {
          "nested": {
            "path": "name",
            "query": {
              "bool": {
                "must": [
                  {"match": {
                    "name.first_name": "wang"
                  }},
 
                  {"match": {
                    "name.last_name": "san"
                  }}
                ]
              }
            }
          }
        }
      ]
    }
  }
}  
# Nested Aggregation

POST student/_search
{
  "size": 0,
  "aggs": {
    "actors": {
      "nested": {
        "path": "name"
      },
      "aggs": {
        "full_name": {
          "terms": {
            "field": "name.first_name",
            "size": 10
          }
        }
      }
    }
  }
}

  

上一篇:MySQL blocked nested loop join(bnl)和index nested loop join(inl)


下一篇:一、Arduino介绍