Skip to content

Instantly share code, notes, and snippets.

@clintongormley
Created March 12, 2014 11:33
Show Gist options
  • Save clintongormley/9505141 to your computer and use it in GitHub Desktop.
Save clintongormley/9505141 to your computer and use it in GitHub Desktop.
curl -XDELETE "http://localhost:9200/myindex"
curl -XPUT "http://localhost:9200/myindex" -d'
{
"mappings": {
"animal": {},
"customer": {
"_parent": {
"type": "animal"
},
"properties": {
"first_name": {
"type": "string",
"index": "not_analyzed"
}
}
},
"visit": {
"_parent": {
"type": "animal"
}
}
}
}'
curl -XPUT "http://localhost:9200/myindex/animal/1" -d'
{
"name": "Fido",
"sex": "neutered"
}'
curl -XPUT "http://localhost:9200/myindex/customer/2?parent=1" -d'
{
"first_name": "Michael"
}'
curl -XPUT "http://localhost:9200/myindex/visit/3?parent=1" -d'
{
"visit_date": "2010-07-28T00:00:00.000ZZ",
"revenue": 100
}'
curl -XPUT "http://localhost:9200/myindex/visit/4?parent=1" -d'
{
"visit_date": "2010-09-28T00:00:00.000ZZ",
"revenue": 150
}'
curl -XGET "http://localhost:9200/_search" -d'
{
"min_score": 1,
"query": {
"function_score": {
"boost_mode": "replace",
"script_score": {
"script": "if (_score < min_rev || _score > max_rev) { 0.0} else { _score}",
"params": {
"min_rev": 200,
"max_rev": 240
}
},
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"animal.sex": "neutered"
}
},
{
"has_child": {
"type": "customer",
"filter": {
"term": {
"first_name": "Michael"
}
}
}
}
]
}
},
"query": {
"has_child": {
"type": "visit",
"score_type": "sum",
"query": {
"function_score": {
"boost_mode": "replace",
"filter": {
"range": {
"visit_date": {
"gt": "2001-07-28T00:00:00.000Z",
"lte": "2011-11-18T00:00:00.000Z"
}
}
},
"script_score": {
"script": "doc[\"revenue\"].value"
}
}
}
}
}
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment