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

ES Learning Notes-the use of template

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

What is the starting point for es to provide template functionality? As a NoSQL database, ES does not set the schema before the data is stored, that is, it does not limit the data fields. This is a good scenario for log-type data. But this practice of not setting schema is sometimes too free. For some business scenarios, we need to set the word segmentation of field in advance. Of course, you can use mappings to solve the problem at this time. But before the service access to inform, first build an index, think a bit unintelligent. Is there a more flexible approach? Templates

Templates is easy to use, but if you want to use it well, there will be no problems or fewer problems, there must be a whole process:

Create template

Curl-XPUT localhost:9200/_template/template_1-d'{"template": "te*", "settings": {"number_of_shards": 1, "number_of_replications": 2}, "mappings": {"type1": {"_ source": {"enabled": false}'

View template

Curl-XGET localhost:9200/_template/template_1?pretty

If there is an error in the creation of templates, delete template

After curl-XDELETE localhost:9200/_template/template_1template is built, to test whether it meets expectations, add a piece of data $curl-XPUT 'http://localhost:9200/template_test/tweet/1'-d' {"user": "kimchy", "post_date": "2009-11-15T14:12:12", "message": "trying out Elasticsearch"}'

Check the status of the cluster. If the shard copy is set incorrectly, the cluster may become yellow.

Curl-XGET 'http://localhost:9200/_cluster/health?pretty=true' View index structure and data samples curl-XGET' http://localhost:9200/twitter/_settings,_mappings?pretty'curl-XGET 'http://localhost:9200/template_test/tweet/1'

After these later verification, we can generally avoid most of the problems.

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

Internet Technology

Wechat

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

12
Report