Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

ES Learning Notes-the use of template

Shulou Source: shulou.com Published: 2022-06-03 07:55:45 09月16日 Update

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.

Tags: Data problem business practice scenario index cluster good free that is starting point copy function field database method log intelligence process status Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia Docker Xiaomi Redmi