O'Reilly logo

Elasticsearch Server Second Edition by Marek Rogoziński, Rafał Kuć

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The terms filter

One of the filters available in Elasticsearch that is very simple at first glance is the terms filter. In its simplest form, it allows you to filter documents to only those that match one of the given terms and is not analyzed. An example use of the terms filter is as follows:

{
  "query" : {
    "constant_score" : {
      "filter" : {
        "terms" : {
          "title" : [ "crime", "punishment" ]
        }
      }
    }
  }
}

The preceding query would result in documents that match the crime or punishment terms in the title field. The way the terms filter works is that it iterates over the provided terms and finds the documents that match these terms. Of course, the matched document identifiers are loaded into a structure called bitset and are cached. Sometimes, we may want ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required