美文网首页
5.4 nested类型

5.4 nested类型

作者: 秦汉邮侠 | 来源:发表于2020-05-23 21:48 被阅读0次

Mappings and Text Analysis

  • Configure an index so that it properly maintains the relationships of nested arrays of objects

文档之间的关系

  • object类型结构性的JSON文档会平整成索引内的一个简单键值格式
  • nested类型,object内部的字段间的关系就能保持

示例

PUT my_index
{
  "mappings": {
    "properties": {
      "user": {
        "type": "nested" 
      }
    }
  }
}


PUT my_index/_doc/1
{
  "group" : "fans",
  "user" : [
    {
      "first" : "John",
      "last" :  "Smith"
    },
    {
      "first" : "Alice",
      "last" :  "White"
    }
  ]
}

GET my_index/_search
{
  "query": {
    "bool": {
      "must": [
        { "match": { "user.first": "Alice" }},
        { "match": { "user.last":  "Smith" }}
      ]
    }
  }
}

GET my_index/_search
{
  "query": {
    "nested": {
      "path": "user",
      "query": {
        "bool": {
          "must": [
            { "match": { "user.first": "Alice" }},
            { "match": { "user.last":  "White" }} 
          ]
        }
      }
    }
  }
}

相关文章

网友评论

      本文标题:5.4 nested类型

      本文链接:https://www.haomeiwen.com/subject/rkqrahtx.html