I am new to Elastic Search. I indexed filmmakers (actors and directors) in ElasticSearch, and a simple text search works fine, for example, if I search for "steven" with the following syntax
{"query": {"query_string": {"query":"steven"} } }
... I get the following results, which are good:
1. Steven Conrad - Popularity (from document) = 487 - elasticsearch _score = 3,2589545 2. Steven Knight - Popularity (from document) = 487 - elasticsearch _score = 3,076738 3. Steven Waddington - Popularity (from document) = 431 - elasticsearch _score = 2,4931839 4. Steven E. De Souza - Popularity (from document) = 534 - elasticsearch _score = 2,4613905 5. Steven R. Monroe - Popularity (from document) = 293 - elasticsearch _score = 2,4613905 6. Steven Mackintosh - Popularity (from document) = 363 - elasticsearch _score = 2,2812681 7. Steven Wright - Popularity (from document) = 356 - elasticsearch _score = 2,2812681 8. Steven Soderbergh - Popularity (from document) = 5947 - elasticsearch _score = 2,270944 9. Steven Seagal - Popularity (from document) = 1388 - elasticsearch _score = 2,270944 10. Steven Bauer - Popularity (from document) = 714 - elasticsearch _score = 2,270944
However, as you can see above, in my document there is a number, the numerical value of popularity , and when you search for "steven", I would like the most popular artists (Stephen Soderbergh, Stephen Seagal ...) to come first.
Ideally, I would like to sort the results above popularity * _score
I am sure that I need to use the function_score function_score for Elastic Search, but I cannot determine the exact syntax.
I tried to perform my "improved" search with the following syntax
{ "query": { "custom_score": { "query": { "query_string": { "query": "steven" } }, "script": "_score * doc['popularity']" } } }
But I get an exception (excerpt from the error message below :)
org.elasticsearch.search.query.QueryPhaseExecutionException: [my_index][4]: query[filtered(function score (_all:steven,function=script[_score * doc['popularity']], params [null]))->cache(_type:artist)],from[0],size[10]: Query Failed [Failed to execute main query] // .... Caused by: java.lang.RuntimeException: uncomparable values <<1.9709579>> and << org.elasticsearch.index.fielddata.ScriptDocValues$Longs@7c5b73bc >> // ... ... 9 more Caused by: java.lang.ClassCastException: org.elasticsearch.index.fielddata.ScriptDocValues$Longs cannot be cast to java.lang.Float at java.lang.Float.compareTo(Float.java:33) at org.elasticsearch.common.mvel2.math.MathProcessor.doOperationNonNumeric(MathProcessor.java:266)
I get the impression that the syntax I'm using is incorrect
What should be the correct syntax? Or is there something else I'm missing? Thank you very much in advance
Edit The display of my table is defined as follows:
"mappings" : { "artist" : { "_all" : { "auto_boost" : true }, "properties" : { "first_name" : { "type" : "string", "index" : "not_analyzed", "analyzer" : "standard" }, "last_name" : { "type" : "string", "boost" : 2.0, "index" : "not_analyzed", "norms" : { "enabled" : true }, "analyzer" : "standard" }, "popularity" : { "type" : "integer" } } } }