Start using ElasticSearch (6) search template

This chapter will be shorter, so I will describe a little knowledge.
The reason why my articles are very short is because I find it difficult to digest long-form articles that do not know how to break them down.
Let me briefly talk about the configuration of the search template, because I personally feel that this piece is relatively independent.

***The Search Template in Elasticsearch allows us to define a query template in advance,

And through parameters to accept the variables passed in from the outside, and then use the built-in Elasticsearch

Mustache script engine for rendering. *

Look at a simple example of executing a query by searching a template

Start using ElasticSearch (6) search template

Very simple query syntax, there are mainly 2 topics:
1.source: define the field name, matching value, length of the
query 2.params: fill in the field name, matching value, and length.
Here it is parameterized with the sql statement in c# Is written exactly the same.

The parsed statement is:

{
"query": { "match" : { "goodsname" : "XPZ1687-TX" } },
"size" : "10"
}

Template definition usage

Earlier, we learned about the basic syntax of templates, so a savvy programmer must think that this is not called a template.
At least we have to save the template, call and pass parameters according to the template number.
This is indeed the case, let me demonstrate it briefly!

Start using ElasticSearch (6) search template
Here I define a template named search_template_v001, which defines a dynamic matching condition for a field.
The source here is no longer filled with the query value, here is the field value we want to return after the query is successful.

Next, see how to call

Start using ElasticSearch (6) search template
The result is returned, and it is simpler than the full table scan, and only the fields defined in the template are returned.
Is not it simple!
Returns the field definition in the template, return later want to modify the field only need to modify the template on it, you do not need to publish a
call to end, and end the query is also flexible.

Guess you like

Origin blog.51cto.com/15034497/2572031