Hey guys,
I am trying to use the rank feature field/query on a nested object field.
The index is like below:
{
"id": {
"type": "integer"
},
"sources": {
"type": "nested",
"properties": {
"source": {
"type": "text"
}
},
"counter": {
"type": "rank_feature"
}
}
}
one of the example document is
{
"id": 1,
"page": "main",
"sources" : [
{
"counter" : 1,
"source" : "main"
},
{
"counter" : 10,
"source" : "browse"
}
}
Can someone please give some advise how to construct the query which can use the counter as rank feature field to boost?
mayya
(Mayya Sharipova)
August 24, 2019, 8:20pm
2
Hello! I am not sure I understand your mapping definition:
"id": {
"type": "integer"
},
"sources": {
"type": "nested",
"properties": {
"source": {
"type": "text"
}
},
"counter": {
"type": "rank_feature"
}
}
Did you intend to put counter under sources
properties, like this:
"id": {
"type": "integer"
},
"sources": {
"type": "nested",
"properties": {
"source": {
"type": "text"
},
"counter": {
"type": "rank_feature"
}
}
}
There is also seems to be a mistake in the json of the doc for indexing that you provided.
About your question how to construct ranked feature query on a nested field, you do it similarly to any other nested query -- you nest it under nested
keyword, like this:
{
"query": {
"nested" : {
"path" : "sources",
"query" : {
"rank_feature": {
"field" : "sources.counter"
}
}
}
}
}
For the boosting based on the rank_feature query, you put in the should
clause, as in the example in the documentation.
{
"query": {
"bool": {
"must": {
"match": {
"page": "main"
}
},
"should": {
"nested": {
"path": "sources",
"query": {
"rank_feature": {
"field": "sources.counter",
"boost" : 0.5
}
},
"score_mode": "max"
}
}
}
}
}
1 Like
system
(system)
Closed
September 21, 2019, 8:20pm
3
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.