skynyrd
3/7/2017 - 7:39 PM

Query Types in Elastic 5

Query Types in Elastic 5

Two types of clauses:

  • Leaf Query: Match, term or range which searches for a given value in a given field.
  • Compound Query: Combines leaf query and other compound query clauses to execute search.

Three general types of queries:

  • Match All
  • Full Text
  • Term Level

Match All

Returns all content with a score of 1.0

POST /index_name/_search
{
  "query" : {
    "match_all" : {...}
  }
}

Full Text

Used for searching bodies of text

Match Query: Matches text with value of field
POST /index_name/_search
{
  "query" : {
    "match" : {
      "name" : "John"
    }
  }
}
MultiMatch Query:
POST /index_name/_search
{
  "query" : {
    "multi_match" : {
      "name" : "John",
      "fields" : ["city", "state"]
    }
  }
}

Term Level Queries

Designed to be used with structured data

Exist:
POST /index_name/_search
{
  "query" : {
    "exists" : {
      "field" : "user"
    }
  }
}
Type:

Match doc based on mapping type.

POST /index_name/_search
{
  "query" : {
    "type" : {
      "value" : "type_name"
    }
  }
}
Range:
POST /index_name/_search
{
  "query" : {
    "range" : {
      "rating" : {
        "gte" : 4
      }
    }
  }
}