Book Image

Elasticsearch Server: Second Edition

Book Image

Elasticsearch Server: Second Edition

Overview of this book

Table of Contents (18 chapters)
Elasticsearch Server Second Edition
Credits
About the Author
Acknowledgments
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Query rewrite


Queries such as the prefix query and the wildcard query—basically, any query that is said to be multiterm—use query rewriting. Elasticsearch does this because of performance reasons. The rewrite process is about changing the original, expensive query to a set of queries that are far less expensive from the Lucene point of view.

An example of the rewrite process

The best way to illustrate how the rewrite process is carried out internally is to look at an example and see what terms are used instead of the original query term. Let's suppose that we have the following data in our index:

curl -XPOST 'localhost:9200/library/book/1' -d '{"title": "Solr 4 Cookbook"}'
curl -XPOST 'localhost:9200/library/book/2' -d '{"title": "Solr 3.1 Cookbook"}'
curl -XPOST 'localhost:9200/library/book/3' -d '{"title": "Mastering Elasticsearch"}'

What we want is to find all the documents that start with the letter s. It's as simple as that; we run the following query against our library index:

curl ...