Elasticsearch Basics
What is mapping in elasticsearch
Mapping is the process of defining how a document, and the fields it contains, are stored and indexed. For instance, use mappings to define: - which fields contain numbers, dates, or geolocations. - which string fields should be treated as full text fields. - the format of date values. - custom rules to control the mapping for dynamically added fields.DATA TYPES IN ELASTICSEARCH
String :-
- text - keywordNumeric :-
- long - integer - short - byte - double - float - half_float - scaled_floatdate :-
- dateboolean :-
- booleanbinary :-
- binaryrange :-
- integer_range - float_range - long_range - double_range - date_rangecomplex datatypes:-
- array - object (for single json) - nested (for arrays of json objects)Geo location :-
- geo_point (for lat/long points) - geo_shape (for complex shapes like polygons)Speciliazed datatypes :-
- IP :- ip for IPv4 and IPv6 addresses - completion :- to provide auto-complete suggestions - token_count :- to count the number of tokens in a string - murmur3 :-to compute hashes of values at index-time and store them in the index - nnotated-text :- to index text containing special markup (typically used for identifying named entities) - percolator :-Accepts queries from the query-dsl - join :- Defines parent/child relation for documents within the same index - alias :-Defines an alias to an existing field. It is often useful to index the same field in different ways for different purposes. For instance, a string field could be indexed as a text field for full-text search, and as a keyword field for sorting or aggregations. Alternatively, you could index a string field with the standard analyzer, the englishanalyzer, and the french analyzer. This is the purpose of multi-fields. Most datatypes support multi-fields via the fields parameter.EXAMPLE MAPPING
curl -X PUT "localhost:9200/index_name" -H 'Content-Type: application/json' -d'
{
"mappings": {
"_doc": {
"properties": {
"user_id": { "type": "integer" },
"user_name": { "type": "text" },
"user_age": { "type": "integer" },
"created": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
}
}
}
'