Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@imotov
Created October 30, 2012 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imotov/3977859 to your computer and use it in GitHub Desktop.
Save imotov/3977859 to your computer and use it in GitHub Desktop.
curl -XDELETE 'http://localhost:9200/test-idx'
echo
echo "Creating parent mappings"
curl -XPUT 'http://localhost:9200/test-idx' -d '
{
"settings": {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
},
"mappings": {
"event": {
"_id": {"index": "not_analyzed"},
"properties" : {
"name": {"type":"string", "store": "yes", "index": "analyzed"}
}
},
"timeframe": {
"_id": {"index": "not_analyzed"},
"_parent": {
"type":"event"
},
"properties" : {
"name": {"type":"string", "store": "yes"}
}
}
}
}'
echo
echo "Creating events"
for i in {1..5}
do
curl -s -XPUT "http://localhost:9200/test-idx/event/$i" -d "{\"name\": \"event $i\"}"
done
echo
echo "Creating events"
for i in {1..5}
do
curl -s -XPUT "http://localhost:9200/test-idx/timeframe/$(((i-1)*2 + 10))?parent=$i" -d "{\"name\": \"timeframe $i of event $(((i-1)*2 + 1))\"}"
curl -s -XPUT "http://localhost:9200/test-idx/timeframe/$(((i-1)*2 + 11))?parent=$i" -d "{\"name\": \"timeframe $i of event $(((i-1)*2 + 2))\"}"
done
echo
echo "Refresh"
curl -XPOST "http://localhost:9200/test-idx/_refresh"
echo
curl "http://localhost:9200/test-idx/event/_search?search_type=query_then_fetch&pretty=true" -d '{
"query": {
"custom_score": {
"query": {
"constant_score":{
"filter": {
"has_child": {
"type": "timeframe",
"query": {
"constant_score": {
"filter": {
"script" : {
"script" : "System.out.println(\"TimeframeFilter(\" + doc.field(\"_id\").value + \")\"); true"
}
}
}
}
}
}
}
},
"script": "System.out.println(\"TimeframeSort(\" + doc.field(\"_id\").value + \")\"); 1.0"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment