How to handle null values ​​in an elastic search field_value_factor

How can I use null for the property for which I want to use field_value_factor? I want popularity weight, but some entries have zero value for this property. Should I set a minimum value of 10 for this property in this data itself? It seems like kludgy.

{ "query": { "function_score": { "query":{ "multi_match" : { "query" : "new girl", "fields" : [ "title^1.2", "name"] } }, "field_value_factor": { "field":"popularity", "modifier":"log1p" }, "boost_mode":"multiply" } } } 
+6
source share
2 answers

The default behavior of ES for null values ​​is not to add a field value at all. However, you can set the default null_value value instead in your mapping. So in your case:

  ... "properties" : { ... "popularity" : { "type" : "integer", "null_value" : "0" # or whatever ... } ... } 

Link: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html

"When a field has (JSON) null, use null_value as the field value. By default, the field is not added at all."

I am surprised that ES does not throw any errors. You must confirm that in fact the documents (or not) have a β€œpopularity” field. Try using Sense?

If you try to compute in a nonexistent field, I am sure that the ES will throw an exception [Missing value for field [x]]. This is both from my own experience and from checking the source code that implements field_value_factor:

https://gitlab.devero.com/development/elasticsearchssl/commit/8fbd1bdd489a9d31d3bda249c3ed9715052e196d

Scroll down to: src / main / java / org / elasticsearch / general / Lucene / search / function / FieldValueFactorFunction.java

and see lines 53-87.

+6
source

For me, the solution was to add the missing property to field_value_factor :

 { "query": { "function_score": { "query": {}, "field_value_factor": { "field": "purchases", "missing": 0 } } } } 

(Note that this was on ES 2.3)

0
source

Source: https://habr.com/ru/post/975445/


All Articles