我有一个名为“书籍”的索引。其中,标题和作者姓名是两个字符串类型的字段。我需要创建一个新字段,这样它就不会在标题中包含作者姓名。
例如:
标题:James Gindal 在 ES 中的高级评分
作者姓名:James Gindal
然后,New_field = ES 中的高级评分。
在 mysql 中,我可以通过简单的字符串 REPLACE() 函数进行更新查询。需要 ES 中的工作解决方案。
最佳答案
使用无痛脚本 _update_by_query
{
"script": {
"inline": "ctx._source.new_field = 'Advanced Scoring in ES by'",
"lang": "painless"
},
"query": {
"bool": {
"must": [{
"term": {
"title": {
"value": "Advanced Scoring in ES by James Gindal"
}
}
},
{
"term": {
"author_name": {
"value": "James Gindal"
}
}
}
]
}
}
}
关于ElasticSearch中的Mysql等价物,根据字段更新字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43561426/