How can I increase the field length norm in the elasticsearch function count?

I know that elasticsearch takes the length of the field into account when calculating the score of documents received on request. The shorter the field, the higher the weight (see Field Length Norm ).

I like this behavior: when searching for iphone I am much more interested in iphone 6 than in Crappy accessories for: iphone 5 iphone 5s iphone 6 .

Now, I would like to try to increase this material, let's say that I want to double its value.

I know that you can change the score using the function score , and I assume that I can achieve what I want through the script score .

I tried to add another field length norm to the table:

  { "query": { "function_score": { "boost_mode": "replace", "query": {...}, "script_score": { "script": "_score + norm(doc)" } } } } 

But I failed by getting this error: [No parser for element [function_score]]

EDIT:

My first mistake was that I did not complete the evaluation of the function in the "request". Now I edited the code above. My new mistake says

 GroovyScriptExecutionException[MissingMethodException [No signature of method: Script5.norm() is applicable for argument types: (org.elasticsearch.search.lookup.DocLookup) values: [<org.elasticsearch.search.lookup.DocLookup@2c935f6f>] Possible solutions: notify(), wait(), run(), run(), dump(), any()]] 

EDIT: I gave the first answer, but I hope for the best

+8
elasticsearch boosting
source share
2 answers

It looks like you could achieve this by using the type token_count field along with the field_value_factor function evaluation .

So, something like this in a field display:

 "name": { "type": "string", "fields": { "length": { "type": "token_count", "analyzer": "standard" } } } 

This will use the number of tokens in the field. If you want to use the number of characters, you can change the analyzer from standard to custom, which symbolizes each character.

Then in the request:

 "function_score": { ..., "field_value_factor": { "field": "name.length", "modifier": "reciprocal" } } 
+8
source share

I have something like that. With the following, I subtract the length of the field of my interests from the estimate.

 { "query": { "function_score": { "boost_mode": "replace", "query": {...}, "script_score": { "script": "_score - doc['<field_name>'].value.length()" } } } } 

Hovever, I can’t control the relative weight of this number, which I subtract, compared to the old account. That is why I do not accept my answer: I will wait better. Ideally, I would like to have access to the field length value within script_score or to get an equivalent result.

+3
source share

All Articles