Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Elasticsearch Mapping Field data types and Management methods

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article focuses on "Elasticsearch mapping field data types and management methods", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "Elasticsearch mapping field data types and management methods" it!

Elasticsearch mapping management

Indexes created in Elasticsearch 6.0.0 or later contain only one mapping type. Indexes created with multiple mapping types in 5.x will continue to run in Elasticsearch 6.x as before. Mapping types will be completely deleted in Elasticsearch 7.0.0

An introduction to mapping

When you create an index, you can pre-define the type and related properties of the field

Es guesses the fields you want to map based on the underlying type of the Json data source, turning the input data into index items that can be searched.

Mapping is a field data type that we define ourselves, while telling es how to index the data and whether it can be searched.

Function: it will make the establishment of the index more detailed and perfect.

1.1 Field data types

String type: text,keyword

Number type: long,integer,short,byte,double,float

Date type: data

Boolean type: boolean

Binary type: binary

Complex types: object (entities, objects), nested (list)

Geo Type: geo-point,geo-shape (Geographic location)

Type of major: ip,competion (search suggestions)

The mapping parameter attribute description is suitable for the type store value: yes for storage, no for no storage, default for noallindexyes for analysis, no for no analysis, default for truetextnull_value if the field is empty, you can set a default value, such as "NA" (pass empty, cannot search, na can search) allanalyzer can set the index and search when using the parser, the default is the standard parser, you can also use whitespace,simple. All English parsers allinclude_in_all default es defines a special field _ all for each document, its function is to let each field be searched. If you want a field not to be searched, you can set it to falseallformat time format string mode date2 to create an index.

Text type will take out words for inverted index, keyword will not be participle, stored as is, matching as is

Once the mapping type is determined, it cannot be modified in the future

# 6.x version no problem PUT books {"mappings": {"book": {"properties": {"title": {"type": "text", "analyzer": "ik_max_word"}, "price": {"type": "integer"} "addr": {"type": "keyword"}, "company": {"properties": {"name": {"type": "text"}, "company_addr": {"type": "text"}, "employee_count": {"type": "integer"} "publish_date": {"type": "date", "format": "yyy-MM-dd"}

After 7.x version

PUT books {"mappings": {"properties": {"title": {"type": "text", "analyzer": "ik_max_word"}, "price": {"type": "integer"}, "addr": {"type": "keyword"} "company": {"properties": {"type": "text"}, "company_addr": {"type": "text"}, "employee_count": {"type": "integer"}, "publish_date": {"type": "date", "format": "yyy-MM-dd"}

Insert data test:

PUT books/_doc/1 {"title": "Big head son thief father", "price": 100," addr ":" Beijing Tiananmen Square "," company ": {" name ":" I love Beijing Tiananmen Square "," company_addr ":" my home is in the Northeast Songhua River silly girl "," employee_count ": 10} "publish_date": "2019-08-19"} # Test data 2PUT books/_doc/2 {"title": "Snow White and the Ten Dwarfs", "price": "99", # string will automatically convert "addr": "Dark Senli", "company": {"name": "my hometown is in Shanghai", "company_addr": "Friends walk together for Life", "employee_count": 10} "publish_date": "2018-05-19"} three View Index # View the mappingGET books/_mapping# of the books index to get all the mappingGET _ all/_mapping here I believe that you have a deeper understanding of "Elasticsearch mapping field data types and management methods". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report