05 - Introduction to Searching

Introduction to Query DSL

GET /reviews/_search
{
  "query": {
    "match_all": {      
    }
  }
}

GET /reviews/_search?q=*

# Search using Request URI
GET /reviews/_search?q=content:Matrix AND author.first_name:taylor

Relevance Score

Using _score provides relavance score of a document

GET /products/_search
{
  "explain": true,
  "query": {
    "term": {
      "name": "lobster"
    }
  }
}

Query Context

  • Query Context - How well do Documents Match ? Gets Relevant Score
  • Filter Context - No relevance scores are calculated. Either a document matches or not. Commonly used for filtering on Dates, Status, Ranges etc.
  • Query context affects relevance, but filter context doesn’t
  • If a query clause should affect relevance use Query context, otherwise use filter context

Full Text Queries and Term Level Queries

Term level queries search for exact matches and hence not analyzed versus full text queries are analyzed

Term level queries will result in zero results because it relies on exact match

GET /products/_search
{
  "query": {
    "term": {
      "name": "Lobster"
    }
  }
}

Whereas full text queries, it will be able to find the match regardless of case.

GET /products/_search
{
  "query": {
    "match": {
      "name": "Lobster"
    }
  }
}