ElasticSearch mapping + exactly match the full-text search inverted index + + internal word's composition

A. Acquaintance mapping

(1) To insert data which directly es, es are automatically indexed, while establishing a corresponding type and Mapping
(2) Mapping the automatically defined data type for each field
(3) of different data types (for example text and date), may be some exact value, some Full text
(4) exact value, at the time of the establishment of inverted index, when the word is the entire value together as a keyword established to inverted index; full text, will experience a variety of processing, segmentation, normaliztion (tense conversion, synonyms conversion, case conversion), will build the inverted index
(5) at the same time it, exact value and full text determines the type of field, in a search over time, the behavior of the exact value field or a full text field for searching is not the same, will be consistent with the establishment of inverted index of behavior; for example, when the exact value of the search, the entire value is a direct follow matching, full text query string, will perform segmentation and normalization again inverted index to search
(6) can be used es of dynam ic mapping, it automatically establish mapping, including automatic data typing; can also be created manually advance the index and type of mapping, its own set of each field, including data types, including the behavior of the index, including the word, and so on

mapping, is a type of metadata index, and each type has its own mapping, determines the data type, create an inverted index of behavior, as well as search behavior

 

Two .mapping core data types, and dynamic mapping

1, the core data types

string
byte,short,integer,long
float,double
boolean
date

2、dynamic mapping

true or false --> boolean
123 --> long
123.45 --> double
2017-01-01 --> date
"hello world" --> string/text

3, View mapping

GET /index/_mapping/type

 

III. Manually create and modify custom string data type mapping and whether word

1, How to Index

analyzed
not_analyzed
no

2, modify the mapping

When establishing mapping index can only be created manually, or new field mapping, but can not update field mapping

PUT /website
{
"mappings": {
"article": {
"properties": {
"author_id": {
"type": "long"
},
"title": {
"type": "text",
"analyzer": "english"
},
"content": {
"type": "text"
},
"post_date": {
"type": "date"
},
"publisher_id": {
"type": "text",
"index": "not_analyzed"
}
}
}
}
}

PUT /website
{
"mappings": {
"article": {
"properties": {
"author_id": {
"type": "text"
}
}
}
}
}

{
"error": {
"root_cause": [
{
"type": "index_already_exists_exception",
"reason": "index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists",
"index_uuid": "co1dgJ-uTYGBEEOOL8GsQQ",
"index": "website"
}
],
"type": "index_already_exists_exception",
"reason": "index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists",
"index_uuid": "co1dgJ-uTYGBEEOOL8GsQQ",
"index": "website"
},
"status": 400
}

PUT /website/_mapping/article
{
"properties" : {
"new_field" : {
"type" : "string",
"index": "not_analyzed"
}
}
}

3、测试mapping

GET /website/_analyze
{
"field": "content",
"text": "my-dogs"
}

GET website/_analyze
{
"field": "new_field",
"text": "my dogs"
}

{
"error": {
"root_cause": [
{
"type": "remote_transport_exception",
"reason": "[4onsTYV][127.0.0.1:9300][indices:admin/analyze[s]]"
}
],
"type": "illegal_argument_exception",
"reason": "Can't process field [new_field], Analysis requests are only supported on tokenized fields"
},
"status": 400
}

四.mapping复杂数据类型以及object类型数据底层结构

1、multivalue field

{ "tags": [ "tag1", "tag2" ]}

建立索引时与string是一样的,数据类型不能混

2、empty field

null,[],[null]

3、object field

PUT /company/employee/1
{
"address": {
"country": "china",
"province": "guangdong",
"city": "guangzhou"
},
"name": "jack",
"age": 27,
"join_date": "2017-01-01"
}

address:object类型

{
"company": {
"mappings": {
"employee": {
"properties": {
"address": {
"properties": {
"city": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"country": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"province": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"age": {
"type": "long"
},
"join_date": {
"type": "date"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}

{
"address": {
"country": "china",
"province": "guangdong",
"city": "guangzhou"
},
"name": "jack",
"age": 27,
"join_date": "2017-01-01"
}

{
"name": [jack],
"age": [27],
"join_date": [2017-01-01],
"address.country": [china],
"address.province": [guangdong],
"address.city": [guangzhou]
}

{
"authors": [
{ "age": 26, "name": "Jack White"},
{ "age": 55, "name": "Tom Jones"},
{ "age": 39, "name": "Kitty Smith"}
]
}

{
"authors.age": [26, 55, 39],
"authors.name": [jack, white, tom, jones, kitty, smith]
}

 

Guess you like

Origin www.cnblogs.com/Transkai/p/11277098.html