Skip to content

Instantly share code, notes, and snippets.

@belevian
Created December 27, 2011 16:27
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 belevian/1524253 to your computer and use it in GitHub Desktop.
Save belevian/1524253 to your computer and use it in GitHub Desktop.
Document boost not applied to numeric fields with ES
#######
# creation of an index foo
#######
curl -XPUT 'http://127.0.0.1:9200/foo/?pretty=true' -d '
{
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
}
'
#Response:
#{
# "ok" : true,
# "acknowledged" : true
#}
#######
# mapping configuration of type bar
#######
curl -XPOST 'http://127.0.0.1:9200/foo/bar/_mapping?pretty=true' -d '
{
"bar" : {
"_boost" : { "name" : "_boost" },
"properties" : {
"id" : { "type" : "integer" },
"tag" : { "type" : "string" }
}
}
}
'
#Response:
#{
# "ok" : true,
# "acknowledged" : true
#}
#######
# index first document
#######
curl -XPOST 'http://127.0.0.1:9200/foo/bar?pretty=true' -d '
{
"_boost" : 1.0,
"id" : 123,
"tag" : "aaa"
}
'
#Response:
#{
# "ok" : true,
# "_index" : "foo",
# "_type" : "bar",
# "_id" : "3W91_rF2Ru-z1jrUn0lyyw",
# "_version" : 1
#}
#######
# index second document
#######
curl -XPOST 'http://127.0.0.1:9200/foo/bar?pretty=true' -d '
{
"_boost" : 2.0,
"id" : 124,
"tag" : "bbb"
}
'
#Response:
#{
# "ok" : true,
# "_index" : "foo",
# "_type" : "bar",
# "_id" : "iWUwuYfMTZyMAglLSwIJuQ",
# "_version" : 1
#}
#######
# search for documents on string fields
#######
curl -XGET 'http://127.0.0.1:9200/foo/bar/_search?pretty=true' -d '
{
"fields" : [],
"query" : {
"bool" : {
"should" : [
{
"term" : {
"tag" : {
"value" : "aaa"
}
}
},
{
"term" : {
"tag" : {
"value" : "bbb"
}
}
}
]
}
}
}
'
#Response:
#{
# "took" : 9,
# "timed_out" : false,
# "_shards" : {
# "total" : 5,
# "successful" : 5,
# "failed" : 0
# },
# "hits" : {
# "total" : 2,
# "max_score" : 0.09001608,
# "hits" : [ {
# "_index" : "foo",
# "_type" : "bar",
# "_id" : "iWUwuYfMTZyMAglLSwIJuQ",
# "_score" : 0.09001608
# }, {
# "_index" : "foo",
# "_type" : "bar",
# "_id" : "3W91_rF2Ru-z1jrUn0lyyw",
# "_score" : 0.04500804
# } ]
# }
#}
# Document boosting works for search on string fields
#######
# search for documents on integer fields
#######
curl -XGET 'http://127.0.0.1:9200/foo/bar/_search?pretty=true' -d '
{
"fields" : [],
"query" : {
"bool" : {
"should" : [
{
"term" : {
"id" : {
"value" : "123"
}
}
},
{
"term" : {
"id" : {
"value" : "124"
}
}
}
]
}
}
}
'
#Response:
#{
# "took" : 2,
# "timed_out" : false,
# "_shards" : {
# "total" : 5,
# "successful" : 5,
# "failed" : 0
# },
# "hits" : {
# "total" : 2,
# "max_score" : 0.5,
# "hits" : [ {
# "_index" : "foo",
# "_type" : "bar",
# "_id" : "3W91_rF2Ru-z1jrUn0lyyw",
# "_score" : 0.5
# }, {
# "_index" : "foo",
# "_type" : "bar",
# "_id" : "iWUwuYfMTZyMAglLSwIJuQ",
# "_score" : 0.5
# } ]
# }
#}
# Document boosting does not work for search on numeric fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment