Created
March 12, 2014 11:33
-
-
Save clintongormley/9505141 to your computer and use it in GitHub Desktop.
This file contains 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
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