Skip to content

Instantly share code, notes, and snippets.

@andreiz
Created June 8, 2012 12:43

Revisions

  1. andreiz revised this gist Jun 8, 2012. 1 changed file with 36 additions and 39 deletions.
    75 changes: 36 additions & 39 deletions percolation
    Original file line number Diff line number Diff line change
    @@ -1,49 +1,46 @@
    curl -XPUT localhost:9200/forum -d'{ index : { number_of_shards : 1, number_of_replicas : 0 } }';

    curl -XPUT localhost:9200/forum/comment/_mapping -d '
    curl -XPUT localhost:9200/shop -d'{ index : { number_of_shards : 1, number_of_replicas : 0 } }';
    curl -XPUT localhost:9200/shop/products/_mapping -d '
    {
    "comment" : {
    "_parent": {
    "type": "post"
    }
    }
    "products" : {
    "properties": {
    "price": {"type": "float"}
    }
    }
    }'

    curl -XPUT 'localhost:9200/forum/post/1' -d '
    {
    "user": "andrei",
    "title": "My ElasticSearch talk"
    curl -XPUT localhost:9200/_percolator/shop/sean -d '{
    "query" : {
    "term" : { "type" : "camera" }
    }
    }'

    curl -XPUT 'localhost:9200/forum/post/2' -d '
    {
    "user": "andrei",
    "title": "My Geotools talk"
    curl -XPUT localhost:9200/_percolator/shop/andrei -d '{
    "query" : {
    "filtered" : {
    "query" : {
    "term" : { "type" : "camera" }
    },
    "filter" : {
    "range" : {
    "price" : { "from": 1, "to" : 200 }
    }
    }
    }
    }
    }'

    curl -XPUT 'localhost:9200/forum/comment/2?parent=1' -d '
    {
    "user": "anon2",
    "text": "that guy had a funny accent"
    # Just percolate
    curl localhost:9200/shop/products/_percolate -d '{
    "doc" : {
    "type" : "camera",
    "brand": "Nikon",
    "price": 250
    }
    }'

    curl -XPUT 'localhost:9200/forum/comment/1?parent=2' -d '
    {
    "user": "anon1",
    "text": "best talk ever!"
    # Index and percolate
    curl -XPOST 'localhost:9200/shop/products?percolate=*' -d '{
    "type" : "camera",
    "brand": "Nikon",
    "price": 150
    }'

    curl 'localhost:9200/forum/_search?pretty=true' -d'
    {
    "query": {
    "top_children" : {
    "type": "comment",
    "query" : {
    "term": {"text": "funny"}
    },
    "score" : "max",
    "factor" : 5,
    "incremental_factor" : 2
    }
    }
    }'
  2. @invalid-email-address Anonymous created this gist Jun 8, 2012.
    31 changes: 31 additions & 0 deletions facets
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    curl 'localhost:9200/conf/speaker/_search?pretty=true' -d'
    {
    "query" : {
    "match_all" : {}
    },
    "size": 0,
    "facets" : {
    "histo1" : {
    "histogram" : {
    "field" : "height",
    "interval" : 10
    }
    }
    }
    }'

    curl 'localhost:9200/dpc/status/_search?pretty=true' -d'
    {
    "query" : {
    "match_all" : {}
    },
    "size": 0,
    "facets" : {
    "histo1" : {
    "date_histogram" : {
    "field" : "created_at",
    "interval" : "hour"
    }
    }
    }
    }'
    139 changes: 139 additions & 0 deletions intro
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,139 @@
    curl -XPOST localhost:9200/conf/speaker/1 -d'
    {
    "name": "Andrei Zmievski",
    "lives": "San Francisco",
    "likes": ["coding", "beer", "photography"],
    "twitter": "a",
    "height": 187
    }';

    curl -XPOST localhost:9200/conf/speaker/2 -d'
    {
    "name": "David Zülke",
    "lives": "Munich",
    "likes": ["coding", "cocktails", "cars", "PHP"],
    "twitter": "dzuelke",
    "height": 188
    }';

    curl -XPOST localhost:9200/conf/speaker/3 -d'
    {
    "name": "Elizabeth Smith",
    "lives": "Baltimore",
    "likes": ["coding", "PHP", "crafts"],
    "twitter": "auroraeosrose",
    "height": 177
    }';

    curl -XPOST localhost:9200/conf/talk/1 -d'
    {
    "name": "ElasticSearch [R]evolution: Welcome",
    "description": "ElasticSearch is quickly becoming one of the primary contenders in the search space: it is distributed, highly available, fast, RESTful, and ready to be plugged into Web applications. Its developers have been busy in the last year; this talk will do a quick introduction to ElasticSearch and cover some of the most interesting and exciting new features. We might even take down a live server or two to illustrate a point."
    }';

    curl -XPOST localhost:9200/conf/talk/2 -d'
    {
    "name": "Designing HTTP Interfaces and RESTful Web Services",
    "description": "A lot of Web Services today claim to be RESTful APIs. But are they really? Do the URLs accurately identify resources? Are the powers of HTTP leveraged properly? What is \"Hypermedia\", what is the Uniform Interface, and what is the secret behind the HATEOAS acronym that is so essential to the REST architectural style? This talk gives answers and guidelines using real-life as well as completely made-up examples to show what REST really is about and why Hypermedia matters."
    }';

    curl -XPOST localhost:9200/conf/talk/3 -d'
    {
    "name": "Event and Signal Programming",
    "description": "Although event driven programming has been around for many years, it''s relatively new as an ''engine'' in the PHP community. But before you can start using it in your code, you should learn the basic patterns and paradigms common to the programming style. Learn from the toolkits that have used event driven programming from the beginning, and look at how to use new PHP 5.4 features to easily apply them to your application."
    }';

    #
    # Search
    #

    curl 'localhost:9200/conf/speaker/_search?pretty=true&q=david'
    curl 'localhost:9200/conf/speaker/_search?pretty=true&q=cars'

    # AND operator
    curl 'localhost:9200/conf/speaker/_search?pretty=true&q=coding+AND+beer'

    # specific field
    curl 'localhost:9200/conf/speaker/_search?pretty=true&q=name:smith'

    # search another type
    curl 'localhost:9200/conf/talk/_search?pretty=true&q=description:php'

    # search across types
    curl 'localhost:9200/conf/speaker,talk/_search?pretty=true&q=php'

    # selective fields
    curl 'localhost:9200/conf/_search?pretty=true&q=php&fields=name,likes'

    # fuzzy
    curl 'localhost:9200/conf/_search?pretty=true' -d'{
    "query": {
    "fuzzy": { "description": "enjinn",
    "prefix_length": 2
    }
    }
    }'

    # boolean and range
    curl 'localhost:9200/_search?pretty=true' -d'{
    "query": {
    "bool": {
    "must": { "term": { "likes": "coding" } },
    "must_not": { "range": { "height": { "lt": 188 } } }
    }
    }
    }'

    # query_string
    curl 'localhost:9200/conf/talk/_search?pretty=true' -d'{
    "query": {
    "query_string": {
    "query": "web -hypermedia",
    "default_operator": "AND",
    "fields": ["description"]
    }
    }
    }'

    curl 'localhost:9200/conf/talk/_search?pretty=true' -d'{
    "query": {
    "query_string": {
    "query": "\"event programming\"",
    "phrase_slop": 2
    }
    }
    }'

    # highlighting
    curl 'localhost:9200/conf/talk/_search?pretty=true' -d'{
    "query": { "term": { "_all": "event" } },
    "highlight": { "fields": { name: {}, description: {} } }
    }'

    # facets
    curl 'localhost:9200/conf/speaker/_search?pretty=true' -d'{
    "query": { "match_all": {} },
    "facets": { "likes": { "terms": { "field": "likes" } } }
    }'

    curl 'localhost:9200/conf/speaker/_search?pretty=true' -d'{
    "query": { "match_all": {} },
    "facets": { "howtall": { "statistical": { "field": "height" } } }
    }'

    # query and filter
    curl 'localhost:9200/_search?pretty=true' -d'{
    "query": {
    "filtered": {
    "query": {
    "term": { "likes": "coding"}
    },
    "filter": {
    "range": {"height": {"gte": 188}}
    }
    }
    }
    }'

    # analyze
    curl 'localhost:9200/places/_analyze/?pretty=true&text=going+fishing&analyzer=eulang'
    49 changes: 49 additions & 0 deletions parent-child
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    curl -XPUT localhost:9200/forum -d'{ index : { number_of_shards : 1, number_of_replicas : 0 } }';

    curl -XPUT localhost:9200/forum/comment/_mapping -d '
    {
    "comment" : {
    "_parent": {
    "type": "post"
    }
    }
    }'

    curl -XPUT 'localhost:9200/forum/post/1' -d '
    {
    "user": "andrei",
    "title": "My ElasticSearch talk"
    }'

    curl -XPUT 'localhost:9200/forum/post/2' -d '
    {
    "user": "andrei",
    "title": "My Geotools talk"
    }'

    curl -XPUT 'localhost:9200/forum/comment/2?parent=1' -d '
    {
    "user": "anon2",
    "text": "that guy had a funny accent"
    }'

    curl -XPUT 'localhost:9200/forum/comment/1?parent=2' -d '
    {
    "user": "anon1",
    "text": "best talk ever!"
    }'

    curl 'localhost:9200/forum/_search?pretty=true' -d'
    {
    "query": {
    "top_children" : {
    "type": "comment",
    "query" : {
    "term": {"text": "funny"}
    },
    "score" : "max",
    "factor" : 5,
    "incremental_factor" : 2
    }
    }
    }'
    49 changes: 49 additions & 0 deletions percolation
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    curl -XPUT localhost:9200/forum -d'{ index : { number_of_shards : 1, number_of_replicas : 0 } }';

    curl -XPUT localhost:9200/forum/comment/_mapping -d '
    {
    "comment" : {
    "_parent": {
    "type": "post"
    }
    }
    }'

    curl -XPUT 'localhost:9200/forum/post/1' -d '
    {
    "user": "andrei",
    "title": "My ElasticSearch talk"
    }'

    curl -XPUT 'localhost:9200/forum/post/2' -d '
    {
    "user": "andrei",
    "title": "My Geotools talk"
    }'

    curl -XPUT 'localhost:9200/forum/comment/2?parent=1' -d '
    {
    "user": "anon2",
    "text": "that guy had a funny accent"
    }'

    curl -XPUT 'localhost:9200/forum/comment/1?parent=2' -d '
    {
    "user": "anon1",
    "text": "best talk ever!"
    }'

    curl 'localhost:9200/forum/_search?pretty=true' -d'
    {
    "query": {
    "top_children" : {
    "type": "comment",
    "query" : {
    "term": {"text": "funny"}
    },
    "score" : "max",
    "factor" : 5,
    "incremental_factor" : 2
    }
    }
    }'
    31 changes: 31 additions & 0 deletions river
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    curl -XPUT 'http://localhost:9200/dpc' -d'{ index : { number_of_shards : 1, number_of_replicas : 0 } }';

    curl -XPUT 'http://localhost:9200/dpc/status/_mapping' -d '
    {
    "tweet" : {
    "properties" : {
    "created_at" : {"type" : "date", "format": "date_time"}
    }
    }
    }
    '

    curl -XPUT localhost:9200/_river/dpc/_meta -d '
    {
    "type" : "twitter",
    "twitter" : {
    "user" : "XXXXXXXXXXXX",
    "password" : "YYYYYYYYYYY",
    "filter" : {
    "tracks" : "#dpc12"
    }
    },
    "index" : {
    "index" : "dpc",
    "type" : "status",
    "bulk_size" : 1
    }
    }
    '

    curl 'http://localhost:9200/dpc/status/_search?pretty=true&q=*&fields=text,user.screen_name,created_at,location'