Skip to content

Instantly share code, notes, and snippets.

@runlevel5
Last active November 12, 2019 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runlevel5/f548825c984cc881d740a483d3ba84b6 to your computer and use it in GitHub Desktop.
Save runlevel5/f548825c984cc881d740a483d3ba84b6 to your computer and use it in GitHub Desktop.
Elasticsearch 7 cheat sheet

How to combine many queries together in query? Simply use bool boolean with must

{
  "query: {
    "bool": {
      "must": [
        { <query 1> },
        { <query 2> }
      ]
    }
  }
}

What about filter? There are 2 ways:

# use filter: [ array of filters ]
{
  "query: {
    "bool": {
      "must": [
        { <query 1> },
        { <query 2> }
      ],
      "filter": [
        { <filter_1> },
        { <filter_2> }
      ]
    }
  }
}

OR using bool with must:

{
  "query: {
    "bool": {
      "must": [
        { <query 1> },
        { <query 2> }
      ],
      "filter": {
        "bool": {
          "must": [
            { <filter_1> },
            { <filter_2> }
          ]
        }
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment