-
-
Save dadoonet/64458f7423863d93c49e 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" | |
] | |
}' | |
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": 1970, | |
"to": 1980 | |
} | |
} | |
} | |
} | |
}, | |
"fields": [ | |
"title" | |
] | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment