Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Honza Kral - Explore Your Data with Elasticsearch

Honza Kral - Explore Your Data with Elasticsearch

NewCircle Training

September 20, 2013
Tweet

More Decks by NewCircle Training

Other Decks in Technology

Transcript

  1. documents # curl -XPUT localhost:9200/stack/question/42 -d '{ “some”: “json” }'

    # curl -XGET localhost:9200/stack/question/42 # curl -XDELETE localhost:9200/stack/question/42
  2. search # curl -XGET localhost:9200/_search?q=meetup # curl -XGET localhost:9200/_search -d

    '{ “query”: { “query_string”: { “query”: “meetup AND title:python” } } }'
  3. queries & filters # curl -XGET localhost:9200/stack/_search -d '{ “query”:

    { “filtered”: { “query”: { “bool”: { “must”: [ {"multi_match": { "fields": ["title^10", "body"] "query": "python" }}, ], “must_not”: [ {“match”: {“title”: “php”} ] } }, “filter”: { “range”:{"creation_date":{"from":"2013-01-01"}} } } } }'
  4. facets # curl -XGET localhost:9200/meetup/_search -d '{ “query”: { ...

    }, “facets”: { “monthly_meetups”: { “date_histogram”: { “field”: “event_date”, “interval”: “month” } }, “attendees_per_topic”: { “terms_stats”: { “key_field”: “topic”, “value_script”: “doc['users'].values.length” } } } }'
  5. mix & match curl -XGET http://localhost:9200/dba.stackexchange.com/question/_search -d ' { "query":

    { "custom_score": { "query": { "filtered": { "query": { "bool": { "must": [ {"multi_match": {"fields": ["title^10", "body"], "query": "mysql"}}, { "has_child": { "child_type": "answer", "query": {"match": {"body": "nosql"}} } } ], "must_not": [ {"multi_match": {"fields": ["title", "body"], "query": "nosql"}} ] } }, "filter": { "range": {"creation_date": {"from": "2012-01-01"}} } } }, "script": "(_score + 1) * doc[\"rating\"].value" } }, "fields": ["title", "rating", "creation_date"], "highlight": { "fields": { "title": {"fragment_size" : 50}, "body": {"fragment_size" : 50} } }, "facets": { "tags": { "terms": {"field": "tags"} }, "frequency": { "date_histogram": {"field": "creation_date", "interval": "month"} } } }' Find questions that • Were asked last year • Contain “mysql” in title or body • Don't contain “nosql” • Have answer that has “nosql” in title or body • Include question rating into score calculation • Highlight matches in html • Aggregate over time and tags • ….
  6. percolator # curl -XPUT localhost:9200/_percolator/stack/meet -d '{ "query" : {

    "term" : { "tile" : "meetup" } } }' # curl -XPUT localhost:9200/stack/question/_percolate -d '{ “doc”: { “title”: “SF Python Meetup” } }'
  7. suggester – auto-complete # curl -X POST 'localhost:9200/music/_suggest' -d '{

    "song-suggest" : { "text" : "n", "completion" : { "field" : "song_suggest" } } }' { "text" : "Nirvana - Nevermind", "score" : 34.0, "payload" : {"artist_id":2321} }
  8. suggester – did you mean? # curl -XPOST 'localhost:9200/_search' -d

    { "suggest" : { "text" : "Johny Walker", "simple_phrase" : { "phrase" : { ... MAGIC HERE ... "direct_generator" : [ { "field" : "body" } ] } } } }' { "text" : "Johnnie Walker", "score" : 0.314295 }