Created
June 8, 2012 12:43
-
-
Save andreiz/2895421 to your computer and use it in GitHub Desktop.
ElasticSearch {R}evolution talk sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} | |
} | |
} | |
}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPUT localhost:9200/shop -d'{ index : { number_of_shards : 1, number_of_replicas : 0 } }'; | |
curl -XPUT localhost:9200/shop/products/_mapping -d ' | |
{ | |
"products" : { | |
"properties": { | |
"price": {"type": "float"} | |
} | |
} | |
}' | |
curl -XPUT localhost:9200/_percolator/shop/sean -d '{ | |
"query" : { | |
"term" : { "type" : "camera" } | |
} | |
}' | |
curl -XPUT localhost:9200/_percolator/shop/andrei -d '{ | |
"query" : { | |
"filtered" : { | |
"query" : { | |
"term" : { "type" : "camera" } | |
}, | |
"filter" : { | |
"range" : { | |
"price" : { "from": 1, "to" : 200 } | |
} | |
} | |
} | |
} | |
}' | |
# Just percolate | |
curl localhost:9200/shop/products/_percolate -d '{ | |
"doc" : { | |
"type" : "camera", | |
"brand": "Nikon", | |
"price": 250 | |
} | |
}' | |
# Index and percolate | |
curl -XPOST 'localhost:9200/shop/products?percolate=*' -d '{ | |
"type" : "camera", | |
"brand": "Nikon", | |
"price": 150 | |
}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment