Is it possible to setup alias for field names in elasticsearch? (Just like how index names can be aliased)
For example: i have a document {'firstname': 'John', 'lastname': 'smith'}
I would like to alias 'firstname' to 'fn'...
Is it possible to setup alias for field names in elasticsearch? (Just like how index names can be aliased)
For example: i have a document {'firstname': 'John', 'lastname': 'smith'}
I would like to alias 'firstname' to 'fn'...
Probably you can try creating an alias on your index with filter on the desired field. Your filter must be written in such a way that it selects all the entries from your field. Please refer Filtered aliases section in here. But I am interested in knowing your use case. Why you want to create alias on particular field.
There is no direct field alias functionality. However, you could rename the fields upon indexing using the index_name property in your mappings.
See here for more information: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html
Just a quick update, Elasticsearch
6.4
came up with feature called Alias Datatype. Check the below mapping and query as sample.Note that the type of the field is
alias
in the below mapping for fieldnamefn
Sample Mapping:
Sample Query:
The idea is to use the
alias
for actual field on which inverted index is created. Note that fields with alias datatype aren't meant forwrite
operations and its only meant for querying purpose.Although you can refer to the link I've mentioned for more details, below are just some of the important points.
single mapping
. Index has to be created post6.xx
version or be created in older version with the settingindex.mapping.single_type: true
querying
,aggregations
,sorting
,highlighting
andsuggestion
operationsalias
of anotheralias
fieldalias
on multiple fields. Single alias, Single field._source
.