您如何在Elasticsearch中将字段映射为通用对象?(无需编制索引) [英] How do you map a field as a generic object in elasticsearch? (doesn't need to be indexed)

查看:73
本文介绍了您如何在Elasticsearch中将字段映射为通用对象?(无需编制索引)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有此数据:

{
  "field1": {
    "foo":"bar"
  }
}

如果可能的话,我想将"field1"映射为Any对象.我不需要将它编入索引,如果这样可以使它更容易.我不知道field1的结构是什么并且可以更改.因此,我应该能够将我的类型更新为:

I would like to map "field1" as an Any object, if possible. I don't need to index it, if that makes it easier. I don't know what the structure of field1 is and can change. So I should be able to update my type to something like:

{
    "field1": {
        "foo": 123
    }
}

这可能吗?现在看来,我必须知道"field1"对象中字段的映射,并且不能偏离它(除了在其中添加新字段).

Is this possible? Right now it seems I have to know the mappings of the fields in the "field1" object and cannot deviate from it (except add new fields inside).

推荐答案

可以告诉ES您的字段映射是什么,但您不需要.告诉ES您的字段有助于确保一致性.

You can tell ES what your field mappings are but you are not required to. Telling ES what your fields are is helpful for ensuring consistency.

也就是说,如果您只是开始向ES发送一个新字段,它将接受它并自动为其创建映射.

That being said, if you just start sending ES a new field it will accept it and create a mapping for it automatically.

在您的示例中,当ES看到值为"bar"的新字段"foo"时,它将自动创建"foo"的映射以键入"string".

In your example when ES sees the new field "foo" with a value of "bar" it's going to automatically create a mapping of "foo" to type "string".

下次发送"foo"时,其值为123 ES仍将接受该字段,但是它将存储为字符串.

The next time you send in "foo" with a value of 123 ES will still accept that field, but it will be stored as a string.

好消息:ES自动允许您执行此操作坏消息:您不能在该字段上运行"Range"查询(SQL等效项为: WHERE FOO> 200 )

Good news: ES automatically allows you to do this Bad news: you can't run "Range" queries on that field (the SQL Equivilent would be: WHERE FOO > 200)

这篇关于您如何在Elasticsearch中将字段映射为通用对象?(无需编制索引)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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