Mapping the same field with different mappings
Sometimes you want to index the same field with different mappings. For example, you want to index the title field both as text and as keyword. You can use the keyword field for an exact match and the text field for text search. You can do this by defining two fields, one with keyword mapping and other with text mapping, as shown next:
{ "properties": { "title_text": { "type": "text" }, "title_keyword": { "type": "keyword" } } }
You can index the document as follows:
{ "title_text" : "Learning Elasticsearch", "title_keyword" : "Learning Elasticsearch" }
While indexing, the same value is used for both the title_text
and title_keyword
fields. The document source will now have two fields with the same value. To avoid data duplication, while indexing and storing the document source, Elasticsearch provides fieldsmapping.
Using fields mapping, the same field can be indexed as both text and keyword. As shown in the mapping...