Skip to content

Instantly share code, notes, and snippets.

@martijnvg
Created January 26, 2014 21:43
Show Gist options
  • Save martijnvg/8639841 to your computer and use it in GitHub Desktop.
Save martijnvg/8639841 to your computer and use it in GitHub Desktop.
has_parent with function_score
curl -XDELETE "http://localhost:9200/_all"
curl -XPUT "http://localhost:9200/test1" -d'
{
"mappings": {
"parent" : {
"properties": {
"weight" : {
"type": "double"
}
}
},
"child" : {
"_parent": {
"type": "parent"
}
}
}
}'
curl -XPUT "http://localhost:9200/test1/parent/1" -d'
{
"weight" : 5
}'
curl -XPUT "http://localhost:9200/test1/child/1?parent=1" -d'
{
"field" : "value"
}'
curl -XPUT "http://localhost:9200/test1/child/2?parent=1" -d'
{
"field" : "value"
}'
curl -XPOST "http://localhost:9200/test1/_search" -d'
{
"query" : {
"has_parent" : {
"query" : {
"function_score" : {
"script_score" : {
"script" : "_score * doc[\"weight\"].value"
}
}
},
"parent_type" : "parent",
"score_type" : "score"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment