Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # CREATE INDEX
- curl -X POST 'http://localhost:9200/bands/' -d '{
- "mappings" : {
- "documents" : {
- "properties" : {
- "title" : {
- "type" : "string"
- },
- "year" : {
- "type" : "integer"
- },
- "xref" : {
- "type" : "nested",
- "properties" : {
- "name" : {
- "type" : "string"
- }
- }
- }
- }
- }
- }
- }'
- # ADD DOCUMENT
- curl -X PUT 'http://localhost:9200/bands/documents/1' -d '
- {
- "title" : "Pink Floyd",
- "year" : "1965",
- "xref" : [
- {
- "name" : "Syd Barrett"
- },
- {
- "name" : "Roger Waters"
- },
- {
- "name" : "David Gilmour"
- },
- {
- "name" : "Nick Mason"
- },
- {
- "name" : "Roger Waters"
- }
- ]
- }'
- # SEARCH DOCUMENT
- curl -XGET "http://localhost:9200/bands/documents/_search?pretty=true" -d '
- {
- "query" : {
- "nested" : {
- "path" : "xref",
- "query" : {
- "bool" : {
- "must" : [
- { "match" : { "xref.name" : "Roger" } }
- ]
- }
- }
- }
- },
- "fields" : [
- "title"
- ]
- }'
- # RESULTS / NO PROBLEM
- {
- "took" : 1,
- "timed_out" : false,
- "_shards" : {
- "total" : 5,
- "successful" : 5,
- "failed" : 0
- },
- "hits" : {
- "total" : 1,
- "max_score" : 1.058217,
- "hits" : [ {
- "_index" : "bands",
- "_type" : "documents",
- "_id" : "1",
- "_score" : 1.058217,
- "fields" : {
- "title" : [ "Pink Floyd" ]
- }
- } ]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment