Skip to content

Latest commit

 

History

History
79 lines (74 loc) · 1.97 KB

04_next_steps.asciidoc

File metadata and controls

79 lines (74 loc) · 1.97 KB

Congratulations, you now understand the fundamentals of the Elasticsearch query DSL. As next steps, you should explore the following queries:

  • The range query allows you to find documents that contain terms within a provided range. For example, if each recipe had a rating, you could add a clause to only return recipes in which rating is greater than or equal to 4.

    GET recipes/_search
    {
      "query": {
        "range": {
          "rating": {
            "gte": 4
          }
        }
      }
    }
  • The match_phrase query allows you to find documents that contain multiple terms in the same order. For example, you could search for olive oil in the ingredients and only get back documents that contain olive oil as an ingredient (not only olive or oil).

    GET recipes/_search
    {
      "query": {
        "match_phrase": {
          "ingredients": "olive oil"
        }
      }
    }
  • The more_like_this query allows you to find documents that are "like" a given set of documents. For example, you could find recipes that are similar to other recipes you like.

    # imagine you like both recipes 152 and 28322
    GET recipes/_doc/152
    GET recipes/_doc/28322
    
    GET recipes/_search
    {
      "query": {
        "more_like_this": {
          "fields": [
            "ingredients"
          ],
          "like": [
            {
              "_index": "recipes",
              "_id": "152"
            },
            {
              "_index": "recipes",
              "_id": "28322"
            }
          ],
          "min_term_freq": 1,
          "max_query_terms": 12
        }
      }
    }

If you are also interested in slicing and dicing your data, you should take the Elasticsearch Aggregations in 15 Minutes course.