嵌套json对象的弹性搜索映射 [英] Elastic search mapping for nested json objects

查看:81
本文介绍了嵌套json对象的弹性搜索映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关嵌套json文档的弹性搜索映射的帮助.我在网上进行了很多搜索,但没有找到任何有用的信息.假设我有这种类型的数据.

  {"name":"Zach",车" : [{"make":土星",型号":"SL"},{"make":"Subaru","model":"Imprezza"}]}{"name":"Bob",车" : [{"make":土星","model":"Imprezza"}]} 

汽车内可以有任意数量的数据对象.根据弹性搜索文档,我了解到嵌套json我必须将类型指定为嵌套.但是没有有关如何在该嵌套类型下指定变量的映射信息的信息.

就像上面的示例一样,我可以这样编写映射.

  {人":{特性":{名称" : {"type":"string"},车":{"type":嵌套"}}}} 

但是如何为 car.make &提供映射信息 car.model ??

这项工作不会出现任何将来的问题吗?

  {人": {特性": {名称" : {"type":"string"},车": {"type":嵌套"特性": {制作": {....},模型": {....}}}}}} 

解决方案

您可以这样做:

  PUT/my_index{映射":{博客":{特性": {注释": {"type":嵌套",特性": {"name":{"type":"string"},"comment":{"type":"string"},"age":{"type":"short"},"stars":{"type":"short"},"date":{"type":"date"}}}}}}} 

引用 ES权威指南的这一部分./p>

I need help regarding elastic search mapping of nested json document. I search in web a lot but didnt find any good to the point info. Suppose I have this type of data..

{
  "name" : "Zach",
  "car" : [
    {
      "make" : "Saturn",
      "model" : "SL"
    },
    {
      "make" : "Subaru",
      "model" : "Imprezza"
    }
  ]
}
{
  "name" : "Bob",
  "car" : [
    {
      "make" : "Saturn",
      "model" : "Imprezza"
    }
  ]
}

where car can have any number of data objects inside. According to the elastic search doc I came to know that for nested json I have to specify the type as nested. But there has no information regarding how I will specify the mapping info of variables under that nested type.

Like in the example above I can write the mapping like this.

{
  "person":{
    "properties":{
      "name" : {
        "type" : "string"
      },
      "car":{
        "type" : "nested"
      }
    }
  }
}

but how to provide mapping info for car.make & car.model??

Will this work fine without any future problem?

{
  "person": {
    "properties": {
      "name" : {
        "type" : "string"
      },
      "car": {
        "type" : "nested"
        "properties": {
          "make": {....},
          "model": {....}
        }
      }
    }
  }
}

解决方案

You can do it like this:

PUT /my_index
{
  "mappings": {
    "blogpost": {
      "properties": {
        "comments": {
          "type": "nested", 
          "properties": {
            "name":    { "type": "string"  },
            "comment": { "type": "string"  },
            "age":     { "type": "short"   },
            "stars":   { "type": "short"   },
            "date":    { "type": "date"    }
          }
        }
      }
    }
  }
}

Quote from this section of the ES definitive guide.

这篇关于嵌套json对象的弹性搜索映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆