1, mapping (mapping) Introduction
Mapping: When creating an index, you can pre-define the type of field and related properties
Elasticsearch guesses the field mappings you want based on the underlying type of the JSON source data, converts the input data into searchable index entries, and mapping is our own defined field data type. Also tells Elasticsearch how to index data and whether it can be searched
Role: will make the index establishment more detailed and perfect
Type: static mapping and dynamic mapping
2. Built-in mapping type (i.e. data type)
String type: Text,keyword two kinds
Text type: Participle, extract stemming, create inverted index
Keyword type: is an ordinary string that can only be matched to search for
Number type: Long,integer,short,byte,double,float
Day Type: Date
BOOL (Boolean) Type: Boolean
Binary (binary) type: binary
Complex Type: object,nested
Geo (region) type: Geo-point,geo-shape
Professional type: ip,competion
3. Attribute Introduction
Store Properties
Index Property
Null_value Property
Analyzer Properties
Include_in_all Property
Format Property
More properties: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-boost.html
4. Create an index (equivalent to create a database), create a table, create a field-set the field type, add data
Description
#创建索引 (set field type) PUT jobbole #创建索引设置索引名称 {"mappings": {#设置mappings映射字段类型 "job ": {#表名称" Properties ": {#设置字段类型" title ": {#title字段 "Type": "Text" #text类型, text type can be participle, create inverted index}, "Salary_min": {#salary_min字段 "Type": "Integer" #integer数字类型}, "city": {#city字段 "type": "Keyword "#keyword普通字符串类型}," Company ": {#company字段, is a nested field" properties ": { #设置嵌套字段类型 "name": {#name字段 "type": "Text" #text类型}, "Company_addr": {#company_addr字段 "type": "Text" #text类型}, "Employee_coun T ": {#employee_count字段" type ":" Integer "#integer数字类型}}}," Publ Ish_date ": {#Publish_date field "type": "Date", #date时间类型 "format": "YYYY-MM-DD" #yyyy-mm-dd format Time Style} , "comments": {#comments字段 "type": "Integer" #integer数字类型}}}}}# Save the document (write data equivalent to the database) PUT JOBBOLE/JOB/1 #索引名称/table/id{"title": "Python Distributed crawler Development", #字段名称: Field value "Salary_mi N ": 15000, #字段名称: Field value" City ":" Beijing ", #字段名称: Field value" Company ": { #嵌套字段 "name": "Baidu", #字段名称: Field value "Company_addr": "Beijing Software Park", #字段名称: Field value "Employee_count": 50 #字段名称: Field value}, "Publish_date": "2017-4-16", #字段名称: Field value "Comments": #字段名称 : Field Value}
Code:
#创建索引 (set field type) PUT jobbole{ "mappings": {"job": {"Properties": {" title": { "type": "Text" } , "Salary_min": { "type": "Integer" }, "city": { "type": "Keyword" }, "Company": { "Properties": {" name": {" type": "Text" }, "Company_addr": { "type": "Text" }, "Employee_count": { "type": "Integer" } } }, "Publish_date": { "type": "Date", "Format": "Yyyy-mm-dd" }, "comments": { "type": "Integer"}}}} #保存文档 ( Equivalent to the database write data) PUT jobbole/job/1{ "title": "Python Distributed crawler Development", "salary_min": 15000, "City": "Beijing", " Company ": {" name ":" Baidu ", " company_addr ":" Beijing Software Park ", " Employee_count ":" , " publish_date ":" 2017-4-16 "," Comments ": 15}
5. Get the Mappings Mapping field type under Index
#获取一个索引下的所有表的mappings映射字段类型GET jobbole/_mapping# Gets the Mappings mapping field type for the specified table under an index jobbole/_mapping/job
"Focus" When you create an index, once you have set a type for the field, you cannot modify it, and if you have to re-create the index to modify it, you must determine the type of the field when you create the index
43 Python distributed crawler build search engine Scrapy explaining-elasticsearch (search engine) mapping mapping management