在弹性搜索中向现有映射添加默认值 [英] Adding default value to existing mapping in elastic search

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

问题描述

我有一个带有映射的索引.我决定在现有映射中添加一个新字段:

I have an index with mapping. I decided to add a new field to existing mapping:

{

  "properties": {
    "sexifield": {
      "type": "keyword",
      "null_value": "NULL"
    }
  }

}

据我了解,当我重新编制索引时,该字段应该出现在现有文档中.因此,当我使用api重新编制索引时:

As far as I understand, the field should appear in existing documents when I reindex. So when I use api to reindex:

{
  "source": {
    "index": "index_v1"
  },
  "dest": {
    "index": "index_v2",
    "version_type": "external"
  }
}

我看到index_v2的映射不包含sexifield,文档也不包含它.此外,此操作还不到60毫秒.

I see that the mapping for index_v2 does not consist sexifield, and documents are not consisting it neither. Also this operation took less than 60ms.

请指出我,我对此一无所知...

Please point me, what I do not understand from it...

将新文档添加到第一个索引(对于没有该字段的实体(通过sexifield),通过java API,因此,也许elastic应该为我添加默认字段)与sexifield,也不会为我创建此附加字段.

Adding the new documents to the first index (via java API, for an entity which has not this field (sexifield), so probably elastic should add me the default one) with sexifield, also does not create me this additional field.

预先感谢您的提示.

致谢

推荐答案

大问题+1(我在解决您的问题时学到了一些东西)

great question +1 ( I learned something while solving your problem)

我不知道在重新编制索引时如何考虑第二个映射(重新编制索引的映射)的答案,但是这是一旦从原始索引完成重新编制索引后,我将如何更新重新编制索引的索引(所有文档).我仍在继续研究,以查看是否有一种方法可以在重新索引时考虑第二个索引的映射中定义的默认值,但现在看看这种解决方案是否有帮助.

I don't know the answer to how to consider the second mapping (reindexed mapping) while reindexing, but here is how I would update the reindexed index (all the documents) once the reindexing is done from original index. I still continue to research to see if there is a way to consider the default values that are defined in the mapping of the second index while reindexing, but for now see if this solution helps..

POST /index_v2/_update_by_query
{
  "script": {
    "lang": "painless",
    "inline": "ctx._source.sexifield = params.null_value",
    "params": {
      "null_value": "NULL"
    }
  }
}

这篇关于在弹性搜索中向现有映射添加默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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