Skip to content

Instantly share code, notes, and snippets.

@zwrss
Last active August 29, 2015 14:01
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 zwrss/aeaf2828f6dd35a1e888 to your computer and use it in GitHub Desktop.
Save zwrss/aeaf2828f6dd35a1e888 to your computer and use it in GitHub Desktop.
curl -XDELETE "http://localhost:9200/t"
curl -XPUT "http://localhost:9200/t" -d'
{
"mappings": {
"P": {
"properties": {
"parstr": {
"type": "string"
}
}
},
"T": {
"_parent": {
"type": "P"
},
"_boost": {
"name": "boosting",
"null_value": 1
},
"properties": {
"boosting": {
"type": "double"
},
"str": {
"type": "string"
}
}
}
}
}'
curl -XPOST "http://localhost:9200/t/P/1" -d'
{
"parstr": "parent one"
}'
curl -XPOST "http://localhost:9200/t/P/2" -d'
{
"parstr": "parent two"
}'
curl -XPOST "http://localhost:9200/t/P/3" -d'
{
"parstr": "parent three"
}'
curl -XPOST "http://localhost:9200/t/T?parent=1" -d'
{
"boosting": 1.0,
"str": "one behind another stays the same"
}'
curl -XPOST "http://localhost:9200/t/T?parent=2" -d'
{
"boosting": 2.0,
"str": "one behind another stays the ugly"
}'
curl -XPOST "http://localhost:9200/t/T?parent=3" -d'
{
"boosting": 1.0,
"str": "one behind another stays the true"
}'
curl -XPOST "http://localhost:9200/t/P/_search?pretty=true" -d'
{
"query": {
"top_children": {
"type": "T",
"query": {
"query_string": {
"query": "one behind another"
}
}
}
}
}'
curl -XDELETE "http://localhost:9200/t"
curl -XPUT "http://localhost:9200/t" -d'
{
"mappings": {
"P": {
"properties": {
"parstr": {
"type": "string"
}
}
},
"T": {
"_parent": {
"type": "P"
},
"properties": {
"boosting": {
"type": "double"
},
"str": {
"type": "string"
}
}
}
}
}'
curl -XPOST "http://localhost:9200/t/P/1" -d'
{
"parstr": "parent one"
}'
curl -XPOST "http://localhost:9200/t/P/2" -d'
{
"parstr": "parent two"
}'
curl -XPOST "http://localhost:9200/t/P/3" -d'
{
"parstr": "parent three"
}'
curl -XPOST "http://localhost:9200/t/T?parent=1" -d'
{
"boosting": 1.0,
"str": "one behind another stays the same"
}'
curl -XPOST "http://localhost:9200/t/T?parent=2" -d'
{
"boosting": 2.0,
"str": "one behind another stays the ugly"
}'
curl -XPOST "http://localhost:9200/t/T?parent=3" -d'
{
"boosting": 1.0,
"str": "one behind another stays the true"
}'
curl -XPOST "http://localhost:9200/t/P/_search" -d'
{
"query": {
"top_children": {
"type": "T",
"query": {
"function_score": {
"query": {
"query_string": {
"query": "one behind another"
}
},
"functions": [
{
"script_score": {
"script": "_score * doc['boosting'].value"
}
}
],
"score_mode": "multiply"
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment