我们的ElasticSearch索引中的文档包含一个名为SourceId
(从不为空)的字段和一个名为CustomCategories
的字段。CustomCategories
字段可以为空,也可以包含1到10个逗号分隔的5字符代码。
我需要将自定义类别代码ABCDE
添加到所有包含SourceId 1、2、3、4、10、15、20、22的文档中。
我可以为此运行什么样的ElasticSearch查询,请记住,如果CustomCategories
字段为空,我只需要用ABCDE
填充它,而如果该字段不为空,我需要将,ABCDE
附加到任何值的末尾?
EDIT 1:根据@jaspreet_chahal的请求,下面是一个示例文档,以及customCategories
字段的Map:
文件
{
"_index": "index123",
"_type": "wls_doc",
"_id": "JqkGxmYBwD-D6of2dr43",
"_score": 1.0,
"_source": {
"address": null,
"age": null,
"aliasList": null,
"caution": null,
"dateOfBirth": null,
"eyeColor": null,
"gender": null,
"hairColor": null,
"height": null,
"identifier": null,
"nationality": null,
"placeOfBirth": null,
"program": null,
"race": null,
"remarks": null,
"text": null,
"weight": null,
"entities": null,
"individualName": "John Doe",
"capturedDateTime": "2018-04-17T01:19:52.0131214",
"sourceId": 1,
"captureId": 194857,
"sourceAgencyAcronym": "ABC",
"sourceAgencyName": "Another Bad Creation",
"sourceCountry": "USA",
"sourceParentAgency": "Contoso",
"sourceRegion": "United States",
"url": "http://www.contoso.org",
"categories": [
"ABCDE",
"FGHIJ",
"KLMNO"
],
"customCategories": [
"XA001",
"XB001"
]
}
}
customCategories字段的Map:
"customCategories": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
1条答案
按热度按时间vof42yt11#
您可以使用update by query和Painless脚本。
数据来源:
查询:
回应: