Hi all,
I want to boost documents that have a certain property in a nested
structure (see mapping) with the corresponding value in the nested
structure.
In the example below i got value pairs of a color and a value. Let's say I
want to boost all documents of a query, that have the color blue and I want
to boost it with the corresponding value of blue in each document (so the
boost should be 1 for doc 1 because the value for blue is 1, 5 for doc 3
because the value for blue is 5, ...). What would be a good way to do so?#
I was trying to use function_score or custom_filters_score ... but I am
stuck on accessing the value for a specific color for a specific document
in mvel. Can someone help me on how to access the the value for boosting?
Or has a different solution on how to solve my problem?
Indexmapping:
curl -XPOST "http://localhost:9200/products" -d'
{
"mappings" : {
"product" : {
"properties" : {
"title" : { "type" : "string"},
"uuid" : { "type" : "double"},
"review" : { "type" : "string"},
"colors" : {
"type" : "nested",
"properties": {
"color" : { "type" : "string"},
"value" : {"type" : "integer"}
}
}
}
}
}
}'
Sample Documents:
curl -XPUT "http://localhost:9200/products/product/1" -d'
{
"title": "1",
"uuid": "1",
"review": "test",
"colors": [{
"color": "blue",
"value": 1
}, {
"color": "yellow",
"value": 2
}, {
"color": "red",
"value": 14
}]
}'
curl -XPUT "http://localhost:9200/products/product/2" -d'
{
"title": "2",
"uuid": "2",
"review": "test",
"colors": [{
"colors": "green",
"value": 1
}, {
"color": "white",
"value": 2
}]
}'
curl -XPUT "http://localhost:9200/products/product/3" -d'
{
"title": "3",
"uuid": "3",
"review": "test",
"colors": [{
"color": "blue",
"value": 5
}, {
"color": "green",
"value": 5
}]
}'
curl -XPUT "http://localhost:9200/products/product/4" -d'
{
"title": "4",
"uuid": "4",
"review": "test",
"colors": [{
"color": "green",
"value": 0
}, {
"color": "blue",
"value": 0
}, {
"color": "red",
"value": 0
}, {
"color": "white",
"value": 0
}]
}'
curl -XPUT "http://localhost:9200/products/product/5" -d'
{
"title": "5",
"uuid": "5",
"review": "test"
}'
Query using function_score - problem is that I am unable to access the
value of the corresponding color.
curl -XGET "http://localhost:9200/products/product/_search?pretty=true" -d'
{
"query" : {
"function_score": {
"boost_mode" : "replace",
"query": {
"match" : { "review" : "test"}
},
"boost" : "2",
"functions": [
{
"filter": {
"nested": {
"path": "colors",
"filter": {
"term" :
{"colors.color" : "blue"}
}
}
},
"script_score" : {
"script" : "_score + doc["value"].value"
}
},
{
"script_score" : {
"script" : "_score"
}
}
],
"score_mode" : "first"
}
}
}'
Or I could use custom_filters_score - but then again - how do I get the
value of the corresponding color?
curl -XGET "http://localhost:9200/products/product/_search?pretty=true" -d'
{
"query" : {
"custom_filters_score": {
"query": {
"match" : { "review" : "test"}
},
"filters": [
{
"filter": {
"nested": {
"path": "colors",
"filter": {
"term" :
{"colors.color" : "blue"}
}
}
},
"boost" : 2
}],
"score_mode" : "max"
}
}
}'
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/8f24d4b0-29a5-43df-b46a-1103c7d0a6bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.