美文网首页ElasticSearch入门elasticsearch玩转大数据
四十五、Elasticsearch初识搜索引擎-object数据

四十五、Elasticsearch初识搜索引擎-object数据

作者: 编程界的小学生 | 来源:发表于2017-07-10 10:49 被阅读274次

1、object field

PUT /company/employee/1
{
  "address" : {
    "country" : "china",
    "province" : "guangdong",
    "city" : "guangzhou"
  },
  "name" : "jack",
  "age" : 27,
  "join_date" : "2017-01-01"
}

address是object类型,里面包含三个字段。

他对应的mapping为:

{
  "company": {
    "mappings": {
      "employee": {
        "properties": {
          "address": {
            "properties": {
              "city": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "country": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "province": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "age": {
            "type": "long"
          },
          "join_date": {
            "type": "date"
          },
          "name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}

2、object类型底层数据结构大揭秘

{
  "address": {
    "country": "china",
    "province": "guangdong",
    "city": "guangzhou"
  },
  "name": "jack",
  "age": 27,
  "join_date": "2017-01-01"
}

对应的底层数据结构为

{
  "name" : [jack],
  "age" : [27],
  "join_date" : [2017-01-01],
  "address.country" : [china],
  "address.province" : [guangdong],
  "address.city" : [guangzhou]
}
{
    "authors": [
        { "age": 26, "name": "Jack White"},
        { "age": 55, "name": "Tom Jones"},
        { "age": 39, "name": "Kitty Smith"}
    ]
}

对应的底层数据结构为

{
  "authors.age" : [26,55,39],
  "authors.name" : [jack,white,tom,jones,kitty,smith]
}

若有兴趣,欢迎来加入群,【Java初学者学习交流群】:458430385,此群有Java开发人员、UI设计人员和前端工程师。有问必答,共同探讨学习,一起进步!
欢迎关注我的微信公众号【Java码农社区】,会定时推送各种干货:


qrcode_for_gh_577b64e73701_258.jpg

相关文章

网友评论

    本文标题:四十五、Elasticsearch初识搜索引擎-object数据

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