Using matching document original score in filter script for custom filters score query - elasticsearch

I want to use "custom filters score" query and use filters to control the score of resulting documents.
I want a way to use the document's original score as computed by ElasticSearch, and then use that score to calculate the final score of the document, which matches the given filters.
Something like "_docScore * 50/100" as a script for a filter, where "_docScore" is the original score of a document that matches the filter.
How to achieve this in ElasticSearch?
Any help is greatly appreciated.
Regards & Thanks,
Aditya.

Documents in a filtered query would be unranked and have the same score.
http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/
But you can use a custom score query together with a filtered query and use a script to calculate a score based on the document values. This was added in 0.90, I believe.

Related

How to search result set from a result set in elasticsearch

Im tring to understand the DSL query i needed if i want to make a search from a result set i got. means i have an initial term search, then i want make another query upon the previous result.
lets say i a have 10 documents with a sharing identifier between them, each document has a description field. i want to search first all the documents containing the value 'Hello' in the description and then take their id's, and search the document containing the value 'good by'.
thanks.
No need to execute two queries, you can use filter context that will filter out the results.filter parameter will filter out documents that do not match, and will also not affect the score for matching documents.
Filter context is in effect whenever a query clause is passed to a
filter parameter, such as the filter or must_not parameters in the
bool query, the filter parameter in the constant_score query, or the
filter aggregation.
Refer this to know more about Query and Filter contexts

Boosting score in Elasticsearch based on aggregation result

I need to boost the score of my documents based on a particular value. That value can be obtained from aggregation query.
Currently I am using 2 queries to do it, would like to achieve it in a single query.
1-So basically first query gets me the highest no of occurrence of a particular chapter based on a simple term/match query.
2- Next step is once I get the highest occurring chapter will fire another query which would basically have the same above query with another term query added with a boost factor of 10.
Any input with this regards is welcomed, if we can accomplish this in one query. Thanks in advance.
Ashit

Is it possible to give fix score for specific field search in elasticsearch

Is it possible to give fix score based on every field match. for e.g one field matched then increment score for document by 1 , second field matched then increment document score by 1, so if there are one fields matched the score would be 1 if two fields matched then score would be 2 and so on...
The best tool for modifying the _score value of a query is the function_score query.
Elasticsearch actually offers many methods for calculating the score for each match. You can use a custom_score query along with a script to access the value of a particular numeric field. Consider this statement:
"script" : "_score * doc['my_numeric_field'].value"
Here, we are giving weight to the value of my_numeric_field by multiplying it with the default _score. You could also use the custom_filters_score_query, in which you apply filters to restrict the result set and then use a script or a boost to assign a score to any documents that match the filter. Similarly, you could apply the custom_boost_factor to any query to multiply the default score of that query with a boost value. In the 0.19.0 release of Elasticsearch, there is a new query that combines all of these into the function_score query.

How can I get response(which is searched by score) in Elasticsearch?

I need your help. I want to a search which can be search by common conditions and its score range also used as conditions。Can I do it successfully? if you know ,I hope you can share.
I have a example in the picture:
In the picture,we know the score range is [0,1] ,if I want to get response which scores is [0.2,0.6],How do it! help! SOS! Execute my English!
Elasticsearch provides a min_score field that can be included in a request body search to filter out documents with a _score less than a specified value.
There is no way to filter out documents with a _score greater than a certain value, but: why do you want to do this? Scores in Lucene by definition mean that documents were found matching your search query, and that some results are more relevant than others. I recommend that you read "What is Relevance?" in the Elasticsearch documentation, and "Apache Lucene - Scoring" for a basic understanding of how the scoring formula works.
Also, the Lucene score range isn't always [0,1]: it can be greater than 1.

filtering out docs that have a word from a stop list

I have a search query for some such as "match":{"product name":"glasses car"} so that I am looking for glasses or cars (or both).
But I want to exclude the docs that have google glass or google car in them. so how would I filter them out?
I could use a bool query and use must_not for google, but then I will lose the scoring and get a constant score.
You should use a filtered query with a filter to exclude words like google and keep your main search as the query.
The filter does not affect scoring, only the query part of the filtered query does.
You can find a small example on the Filtered Query page in the ElasticSearch documentation.

Resources