Skip to content

Instantly share code, notes, and snippets.

@sunary
Last active December 15, 2016 04:32
Show Gist options
  • Select an option

  • Save sunary/5d17476afb88618d3d0eaf3d6e026845 to your computer and use it in GitHub Desktop.

Select an option

Save sunary/5d17476afb88618d3d0eaf3d6e026845 to your computer and use it in GitHub Desktop.
elasticsearch tips and tricks

order:

index > type > documents

filter vs query

  • filter: boolean, exactly value, no score, cached, faster
  • query: relevent, full text, score, not cached, slower

term vs match

  • term: analyzed
  • match: not analyzed, date, integer

AND NAND OR

  • bool > must: AND
  • bool > must_not: NAND
  • bool > should: OR
  • filter > terms: mutil values

compare

  • range > from
  • range > to

demo:

GET index/type/_search
{
   "filter": {
      "and": {
         "filters": [
            {
               "term": {
                  "date": "8_7_2015"
               }
            },
            {
               "range": {
                  "count": {
                     "gt": 1
                  }
               }
            }
         ]
      }
   }
}
GET index/type/_search
{
   "aggs": {
      "by_pkg": {
         "terms": {
            "field": "bundleid_pkg"
         }
      }
   }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment