Skip to content

Instantly share code, notes, and snippets.

@hkorte
Created September 17, 2013 09:51
Show Gist options
  • Save hkorte/6592285 to your computer and use it in GitHub Desktop.
Save hkorte/6592285 to your computer and use it in GitHub Desktop.
Defining a field as boost removes this field's properties. Thus, it is impossible to sort on the boost field. The last search with sorting the bothdocs shows the problem with "sort" : [ "-Infinity" ].
curl -XDELETE 'http://localhost:9200/boosttest'
curl -XPOST 'http://localhost:9200/boosttest' -d '{
"mappings" : {
"sortdoc": {
"properties" : {
"my_boost":{
"type":"float"
}
}
},
"boostdoc": {
"_boost" : {
"name" : "my_boost",
"null_value" : 1.0
}
},
"bothdoc": {
"_boost" : {
"name" : "my_boost",
"null_value" : 1.0
},
"properties" : {
"my_boost":{
"type":"float"
}
}
}
}
}'
curl -XGET 'http://localhost:9200/boosttest/sortdoc/_mapping?pretty=true'
curl -XGET 'http://localhost:9200/boosttest/boostdoc/_mapping?pretty=true'
curl -XGET 'http://localhost:9200/boosttest/bothdoc/_mapping?pretty=true'
curl -XPUT 'http://localhost:9200/boosttest/sortdoc/1' -d '{ "text": "test tast tost", "my_boost": 15.0 }'
curl -XPUT 'http://localhost:9200/boosttest/sortdoc/2' -d '{ "text": "test tast tost", "my_boost": 5.0 }'
curl -XPUT 'http://localhost:9200/boosttest/sortdoc/3' -d '{ "text": "test tast tost", "my_boost": 25.0 }'
curl -XPUT 'http://localhost:9200/boosttest/sortdoc/4' -d '{ "text": "test tast tost", "my_boost": 100.0 }'
curl -XPUT 'http://localhost:9200/boosttest/sortdoc/5' -d '{ "text": "test tast tost", "my_boost": 20.0 }'
curl -XPUT 'http://localhost:9200/boosttest/boostdoc/1' -d '{ "text": "test tast tost", "my_boost": 15.0 }'
curl -XPUT 'http://localhost:9200/boosttest/boostdoc/2' -d '{ "text": "test tast tost", "my_boost": 5.0 }'
curl -XPUT 'http://localhost:9200/boosttest/boostdoc/3' -d '{ "text": "test tast tost", "my_boost": 25.0 }'
curl -XPUT 'http://localhost:9200/boosttest/boostdoc/4' -d '{ "text": "test tast tost", "my_boost": 100.0 }'
curl -XPUT 'http://localhost:9200/boosttest/boostdoc/5' -d '{ "text": "test tast tost", "my_boost": 20.0 }'
curl -XPUT 'http://localhost:9200/boosttest/bothdoc/1' -d '{ "text": "test tast tost", "my_boost": 15.0 }'
curl -XPUT 'http://localhost:9200/boosttest/bothdoc/2' -d '{ "text": "test tast tost", "my_boost": 5.0 }'
curl -XPUT 'http://localhost:9200/boosttest/bothdoc/3' -d '{ "text": "test tast tost", "my_boost": 25.0 }'
curl -XPUT 'http://localhost:9200/boosttest/bothdoc/4' -d '{ "text": "test tast tost", "my_boost": 100.0 }'
curl -XPUT 'http://localhost:9200/boosttest/bothdoc/5' -d '{ "text": "test tast tost", "my_boost": 20.0 }'
curl -XPOST 'http://localhost:9200/boosttest/_refresh'
curl -XPOST 'http://localhost:9200/boosttest/sortdoc/_search?pretty=true' -d '{
"query": {
"match_all": {}
},
"sort": [
{
"my_boost": {
"order": "desc"
}
}
]
}'
curl -XPOST 'http://localhost:9200/boosttest/boostdoc/_search?pretty=true' -d '{
"query": {
"term": {
"text": {
"value": "test"
}
}
}
}'
curl -XPOST 'http://localhost:9200/boosttest/bothdoc/_search?pretty=true' -d '{
"query": {
"term": {
"text": {
"value": "test"
}
}
}
}'
curl -XPOST 'http://localhost:9200/boosttest/bothdoc/_search?pretty=true' -d '{
"query": {
"match_all": {}
},
"sort": [
{
"my_boost": {
"order": "desc"
}
}
]
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment