Last active
August 29, 2015 14:03
-
-
Save saiglen/ad8b89836547c7e0ee60 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
echo "\n Delete old index" | |
curl -X DELETE 'http://localhost:9200/bands' | |
echo "\n Create Index Mapping" | |
curl -X POST 'http://localhost:9200/bands/' -d '{ | |
"mappings" : { | |
"documents" : { | |
"properties" : { | |
"title" : { | |
"type" : "string" | |
}, | |
"year" : { | |
"type" : "integer" | |
}, | |
"xref" : { | |
"type" : "nested", | |
"properties" : { | |
"name" : { | |
"type" : "string" | |
} | |
} | |
} | |
} | |
} | |
} | |
}' | |
echo "\n Verify Mapping" | |
curl 'http://localhost:9200/_mapping?pretty' | |
echo "\nAdd Pink Floyd" | |
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" | |
} | |
] | |
}' | |
echo "\n Add Queen" | |
curl -X PUT 'http://localhost:9200/bands/documents/2' -d ' | |
{ | |
"title" : "Queen", | |
"year" : "1970", | |
"xref" : [ | |
{ | |
"name" : "Freddie Mercury" | |
}, | |
{ | |
"name" : "Brian May" | |
}, | |
{ | |
"name" : "John Deacon" | |
}, | |
{ | |
"name" : "Roger Taylor" | |
} | |
] | |
}' | |
echo "\n Refresh Index" | |
curl -XGET "http://localhost:9200/bands/_refresh" | |
echo "\n XREF Search 'Roger' - (2 Results)" | |
curl -XGET "http://localhost:9200/_search?pretty=true" -d ' | |
{ | |
"query" : { | |
"nested" : { | |
"path" : "xref", | |
"query" : { | |
"bool" : { | |
"must" : [ | |
{ "match" : { "xref.name" : "Roger" } } | |
] | |
} | |
} | |
} | |
}, | |
"fields" : [ | |
"title" | |
] | |
}' | |
echo "\n XREF Search 'Roger' & '1967' - (1 Result)" | |
curl -XGET "http://localhost:9200/bands/_search?pretty=true" -d' | |
{ | |
"query": { | |
"filtered": { | |
"query": { | |
"nested": { | |
"path": "xref", | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"match": { | |
"xref.name": "Roger" | |
} | |
} | |
] | |
} | |
} | |
} | |
}, | |
"filter": { | |
"range": { | |
"year": { | |
"from": 1960, | |
"to": 1969 | |
} | |
} | |
} | |
} | |
}, | |
"fields": [ | |
"title" | |
] | |
}' | |
echo "\n XREF Search 'Roger' & '1967' & 'Floyd' - (1 Result)" | |
curl -XGET "http://localhost:9200/bands/_search?pretty=true" -d' | |
{ | |
"query": { | |
"filtered": { | |
"query": { | |
"nested": { | |
"path": "xref", | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"match": { | |
"xref.name": "Roger" | |
} | |
} | |
] | |
} | |
} | |
} | |
}, | |
"filter": { | |
"and": { | |
"filters": [ | |
{ | |
"range": { | |
"year": { | |
"from": 1960, | |
"to": 1969 | |
} | |
} | |
}, | |
{ | |
"term": { "title" : "Floyd" } | |
} | |
] | |
} | |
} | |
} | |
}, | |
"fields": [ | |
"title" | |
] | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment