DevOps Classroom Series – 27/Sept/2021

Queries in Elastic Search

  • The following structured or term level queries can be done in Elastic search
    • Range Query
    • Exists Query
    • Term Query
    • Terms Query
  • Range Query on numeric types:
    • Lets try to create a query to get the products between price 1000 to 10000
      GET /flipkart/_search
      {
      "query": {
          "range": {
          "discounted_price": {
              "gte": 1000,
              "lte": 10000
          }
          }
      }
      }
    
  • Range Query on dates
GET /flipkart/_search
{
  "query": {
    "range": {
      "fetched_date": {
        "gte": "15/03/2016",
        "lte": "30/03/2016",
        "format": "dd/MM/yyyy"
      }
    }
  }
}
  • Exists query
GET /flipkart/_search
{
  "query": {
    "exists": {
      "field": "fetched_date"
    }
    
  }
}

  • Full text search queries with match
GET /flipkart/_search
{
  "query": {
    "match": {
      "name": "Women's"
    }
    
  }
}

  • Operator
GET /flipkart/_search
{
  "query": {
    "match": {
      "name": {
        "query": "Women's FabHome",
        "operator": "and"
        
      }
      
    }
    
  }
}

  • match phrase:
GET /flipkart/_search
{
    "query" : {
        "match_phrase" : {
            "description": {
                "query": "phone for all"
            }
        }
    }
}
  • Multple fields:
GET /flipkart/_search
{
  "query": {
    "multi_match": {
      "query": "Women's",
      "fields": ["name", "discounted_price"]
    }
  }
}
  • Bool query
GET /flipkart/_search
{
  "query": {
    "bool": {
      "must": [
        {}
      ],
      "should": [
        {}
      ],
      "filter": [
        {}
      ],
      "must_not": [
        {}
      ]
      
    }
  }
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Customized Social Media Icons from Acurax Digital Marketing Agency

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube