For the first contact with elasticsearch children's shoes, in order to facilitate the understanding of the Elasticsearch and MySQL in contrast to explain:
The index in ES is the equivalent of MySQL db, a MySQL can have multiple db, similar, an ES cluster can have multiple index.
The type in ES is the equivalent of a table in MySQL, where a db in MySQL can have multiple tables that store one of our data in a table.
The type corresponding to the mapping in Es, which corresponds to the table structure in MySQL, defines the data type of the different fields.
That is, summarize:
When we want to store some of our business data in ES, we need 1 to build a index;2, create a corresponding type in this index, define its data format mapping;3, and then store our data in ES after the first two steps are successful.
1. Establish index
" Localhost:9200/hot_rank_201802?pretty " # hot_rank_201802 is the index name
2. Build type and build mapping
#hot_rank_201802 is the index name Baidu_hot_search_rank is the type name-D followed by the corresponding MySQL table structureCurl-xput'Localhost:9200/hot_rank_201802/_mapping/baidu_hot_search_rank?pretty'-H'Content-type:application/json'-D'{ "Properties": { "Long_rank": { "type":"Long" }, "Kw_topic": { "type":"keyword" }, "Kw_url": { "type":"keyword" }, "Kw_mark": { "type":"keyword" }, "Long_searchindex": { "type":"Long" }, "Date_grabat": { "type":"Date" }, "Kw_relatednewsurl": { "type":"keyword" }, "Kw_relatedvideourl": { "type":"keyword" }, "Kw_relatedimgurl": { "type":"keyword" } }}'
After these two steps, we have successfully established our data table in ES.
Create index in Elasticsearch and add type definition mapping