Query rewrite
When debugging your queries, it is very valuable to know how all the queries are executed. Because of that, we decided to include the section on how query rewrite works in Elasticsearch, why it is used, and how to control it. If you have ever used queries, such as the prefix
query and the wildcard
query, basically any query that is said to be multiterm (a query that is built of multiple terms), you've used query rewriting even though you may not have known about it. Elasticsearch does rewrite for performance reasons. The rewrite process is about changing the original, expensive query into a set of queries that are far less expensive from an Apache Lucene point of view, thus speeding up the query execution.
Prefix query as an example
The best way to illustrate how the rewrite process is done internally is to look at an example and see which terms are used instead of the original query term. We will index three documents to our library_it
index by using the following commands:
...