有 2 个步骤——dynamic_mapping https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html and an ingest_pipeline https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest-apis.html.
我假设你的领域c
是不平凡的,因此您可能希望使用动态模板中的该字段来匹配match https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html#match-unmatch并分配keyword
映射到它:
PUT synthetic
{
"mappings": {
"dynamic_templates": [
{
"c_like_field": {
"match_mapping_type": "string",
"match": "c*",
"mapping": {
"type": "keyword"
}
}
}
],
"properties": {
"a": {
"type": "long"
},
"b": {
"type": "long"
}
}
}
}
然后你可以设置一个管道来连接你的a
& b
:
PUT _ingest/pipeline/combined_ab
{
"description" : "Concatenates fields a & b",
"processors" : [
{
"set" : {
"field": "c",
"value": "{{_source.a}}_{{_source.b}}"
}
}
]
}
摄取新文档后(使用激活的管道!)
POST synthetic/_doc?pipeline=combined_ab
{
"a": 531351351351,
"b": 251531313213
}
我们可以走了:
GET synthetic/_search
yields
{
"a":531351351351,
"b":251531313213,
"c":"531351351351_251531313213"
}
验证w/GET synthetic/_mapping
too.