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

Compound queries


In the Basic queries section of this chapter, we discussed the simplest queries exposed by Elasticsearch. However, the simple ones are not the only queries that Elasticsearch provides. The compound queries, as we call them, allow us to connect multiple queries together or alter the behavior of other queries. You may wonder if you need such functionality. A simple exercise to determine this would be to combine a simple term query with a phrase query in order to get better search results.

The bool query

The bool query allows us to wrap a virtually unbounded number of queries and connect them with a logical value using one of the following sections:

  • should: The bool query when wrapped into this section may or may not match—the number of should sections that have to match is controlled by the minimum_should_match parameter

  • must: The bool query when wrapped into this section must match in order for the document to be returned

  • must_not: The bool query when wrapped into this section...