I'm a bit confused how to best handle the following scenario with Elasticsearch. I've different types of documents, which have fields with semantically the same content but different field names (see examples). Field type-a.a should be handled like type-b.b or type-c.c.
As far as I know an alias for multiple fields is not supported (enter link description here).
Document 1:
{
"id": 1,
"type-a": {
"a": 300
}
}
Document 2:
{
"id": 2,
"type-b": {
"b": 200
}
}
Document 3:
{
"id": 3,
"type-c": {
"c": 200
}
}
Is there a way to map this fields to common field? What would be best practice? Denormalize the fields before ingesting it to the index?
Thanks for any ideas!
You might achieve what you want using the
copy_to
mapping parameter. You can declare each semantically equivalent field to copy its value to another field.Your mapping would look like this:
Then let's say you index the following data, all documents will have their
equivalent
integer field populated with the value of the type-specific fielda
,b
orc
:You can finally search your index using the
equivalent
integer field, regardless of the type of the document. The following query will return all three documents above: