在弹性搜索中创建或更新映射 [英] Create or update mapping in elasticsearch

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

问题描述

我是Elasticsearch的新手,目前正在努力实施一个 geo_distance 过滤器进行搜索。到目前为止,我的索引具有以下映射(我已经删除了一些字段):

  {
advert_index:{
映射:{
advert_type:{
属性:{
__v:{
类型:long
},
caption:{
类型:string
},
类别:{
类型:string
},
**位置:{
键入:long
},**

}
}
}
}
pre>

geo_distance字段将在位置字段中实现,示例实例如下所示:

 location:[
71,
60
],

即可是在geoJSON格式 [lon,lat]



我了解到,我将不得不更新我的索引,以便位置字段的类型为 geo_point ,如上所述在文档中(映射地理位置) 。似乎我必须删除索引并创建一个新的索引,但是我不能这样做。我在正确的轨道上吗?



如果任何人可以帮助我创建一个新的索引或更新我现有的索引数据类型,我将非常感谢。



非常感谢!

解决方案

一般来说,您可以更新索引映射使用 put mapping api(参考 here ):

  curl -XPUT'http:// localhost:9200 / advert_index / _mapping / advert_type'-d'
{
advert_type:{
properties:{

//您的新映射属性

}
}
}
'

有用于添加新字段。但是,在您的情况下,您将尝试更改位置类型,这将导致冲突,并阻止使用新的映射。



您可以使用put mapping api将添加另一个包含位置的属性作为lat / lon数组,但是您将无法更新以前的位置字段本身。



最后,您将需要重新索引您的数据,以便将您的新映射考虑在内。



最佳解决方案将是



如果创建另一个索引的问题是停机,您应该看看aliases 使事情顺利进行。


I am new to Elasticsearch and am currently working on implementing a geo_distance filter for searching. As of now my index has the following mapping (I've removed some fields):

{
advert_index: {
   mappings: {
      advert_type: {
         properties: {
            __v: {
               type: "long"
            },
            caption: {
               type: "string"
            },
            category: {
               type: "string"
            },
            **location: {
            type: "long"
            },**

         }
      }
   }
}

The geo_distance field is going to be implemented on the location field, where an example instance looks like this:

"location": [
               71,
               60
            ],

I.e. is on geoJSON format [lon, lat].

I understand that I will have to update my index so that the location field is of type geo_point, as described in the documentation (mapping-geo-point). It seems like I have to drop the index and create a new one, but I am not able to do this.

Am I on the right track? I would greatly appreciate it if anyone could help me with how I could create a new index or update my existing one with the correct data type.

Many thanks!

解决方案

Generally speaking, you can update your index mapping using the put mapping api (reference here) :

curl -XPUT 'http://localhost:9200/advert_index/_mapping/advert_type' -d '
{
    "advert_type" : {
        "properties" : {

          //your new mapping properties

        }
    }
}
'

It's especially useful for adding new fields. However, in your case, you will try to change the location type, which will cause a conflict and prevent the new mapping from being used.

You could use the put mapping api to add another property containing the location as a lat/lon array, but you won't be able to update the previous location field itself.

Finally, you will have to reindex your data for your new mapping to be taken into account.

The best solution would really be to create a new index.

If your problem with creating another index is downtime, you should take a look at aliases to make things go smoothly.

这篇关于在弹性搜索中创建或更新映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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