This article mainly explains some of mapping's related configuration and need to pay attention to the place, said mapping everyone may feel somewhat puzzled, in fact, I can generally understand elasticsearch as an RDBMS (relational database, such as MySQL), then index The equivalent of a database instance, type can be understood as a table, so that mapping can be understood as the structure of the table and related information about the settings (of course mapping have a broader meaning).
The default does not require an explicit definition of mapping, and when a new type or field is introduced, Elasticsearch automatically creates and registers a mapping with a reasonable default value (no performance pressure), and only the mapping definition must be provided to overwrite the default value. What is mapping
First look at the definitions in the official documentation
A mapping defines the fields within a type, the datatype for each field, and how the field should is handled by Elasticsea Rch. A mapping is also used to configure metadata associated with the type.
Mapping defines the data types of many fields in the type and how those fields are elasticsearch processed, such as whether a field can be queried and how to participle. Custom Mapping
The following is a simple mapping definition:
curl-xput ' Http://localhost:9200/megacorp '-d ' {"Settings": {"Number_of_shards":
3, "Number_of_replicas": 1}, "mappings": {"employee": {"Properties": {
"First_Name": {"type": "String"}, "Last_Name": {
' Type ': ' String '}, ' age ': {' type ': ' Integer '
}, "about": {"type": "String"}, "interests": {
"Type": "String"}, "Join_time": {"type": "Date",
"Format": "Dateoptionaltime", "index": "Not_analyzed"} }
}
}
}
'
Where employee is type (equivalent to a table in a relational database), we define the 6 attributes of first_name, last_name, age, about, interests, join_time in employee.
{"Interests": {"type": "String"}
Type represents the data type of field, and the type of interests in the previous example is a string representation of normal text.
Elasticsearch supports the following data types: text: string number: Byte, short, integer, long floating point: float, double boolean: Boolean date:date
For a field of type string, the most important property is: Index and analyzer.
1. Index
The Index property controls how a string is indexed, and it has three optional values: Analyzed:first analyze the string, then index it. In other words,
Index This field as full text. Not_analyzed:: Index This field, so it was searchable, but index the
Value exactly as specified. does not analyze it. No:don ' t index this field at all. This field won't be
Searchable.
For string type filed index the default value is: analyzed. If we want to do an exact lookup, we need to set it to: not_analyzed.
For example:
{"tag": {"type": "string", "index": "Not_analyzed"}
2. Analyzer
For fields of type string, we can use the Analyzer property to specify which word breaker to use during the search and indexing stages. By default, Elasticsearch uses standard Analyzer, and you can also specify other Elasticsearch built-in, such as whitespace, simple, or 中文版:
For example:
{"tweet": {"type": "String", "Analyzer": "中文版"}