# First, we start to add several documents
PUT /myindex/article/1
{
"post_date": "2020-03-14",
"title": "Java",
"content": "java is the best language",
"author_id": 119
}
PUT /myindex/article/2
{"post_date": "2020-03-14" ,
"title": "html",
"content": "I like html",
"author_id": 120
}
PUT /myindex/article/3
{"post_date": "2020-03-14" ,
"title": "es",
"content": "Es is distributed document store" ,
"author_id": 110
}
#查看es的文档映射mapping的数据结构
GET /myindex/article/_mapping
mapping data structure is as follows:
{
"myindex" : {
"mappings" : {
"article" : {
"properties" : {
"author_ id" : {
"type" : "long"
},
"content" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"post_ _date" : {
"type" : "date"
},
"post_ date" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
Here we did not do a data structure is defined as an index of documents, but we found es automatically create a corresponding index type and type mapping (dynamic mapping) Description ElasticSearch can automatically detect according to our data and given the field's data type
If a given true, false ------> boolean
If the given string "string" ------> string (note that I use is the 6.8.6 version of the string has been replaced by text or keyword)
If a given number 1,2 ------> long
If a given number of decimal 12.34 ------> double
If a given time 2020-03-14 -------> date
What is mapping mapping?
mapping defines a data type of each field and how these fields and other related properties word
We now with inquiries about the content of the document added GET / myindex / article / _search
{
"took" : 29,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [
{
"_index" : "myindex",
"_type" : "article",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"post_ date" : "2020-03-14",
"title" : "html",
"content" : "I like html",
"author_ id" : 120
}
},
{
"_index" : "myindex",
"_type" : "article",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"post_ date" : "2020-03-14",
"title" : "Java",
"content" : "java is the best language",
"author_ id" : 119
}
},
{
"_index" : "myindex",
"_type" : "article",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"post_ _date" : "2020-03-14",
"title" : "es",
"content" : "Es is distributed document store",
"author_ id" : 110
}
}
]
}
}
Queries with conditions
# Check out
GET / myindex / article / _search q = post_date:? 2020
# Can check out
? GET / myindex / article / _search q = post_date: 2020-03-14
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [
{
"_index" : "myindex",
"_type" : "article",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"post_date" : "2020-03-14",
"title" : "html",
"content" : "I like html",
"author_id" : 120
}
},
{
"_index" : "myindex",
"_type" : "article",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"post_date" : "2020-03-14",
"title" : "Java",
"content" : "java is the best language",
"author_id" : 119
}
},
{
"_index" : "myindex",
"_type" : "article",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"post_date" : "2020-03-14",
"title" : "es",
"content" : "Es is distributed document store",
"author_id" : 110
}
}
]
}
}
# You can check out the
GET / myindex / article / _search q = content:? Html
note?
This is because ElasticSearch map mapping specifying, post_date date type, content type is a string so the string to check out. Dates and date types like digital long to type a query can query accurate, and indicating the date and numeric types no word, and the word string. The default text string type has been word of
Here we know the mapping has two roles, one Provisions given type, the second is defined attributes related fields (such as word is not carried out)