Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly I'd like to say that there are many ways of customising the scoring in elasticsearch and it seems like you may have accidentally picked the wrong one. I will just summarize two and you will see what the problem is:</p> <h2>Custom Filters Score</h2> <p>If you <a href="http://www.elasticsearch.org/guide/reference/query-dsl/custom-filters-score-query/" rel="nofollow">read the docs</a> (carefully) on <code>custom_filters_score</code> then you will see that it there for performance reasons, to be able to use for scoring the the faster filter machinery of elasticsearch. (Filters are faster as scoring is not calculated when computing the hit set, and they are cached between requests.)</p> <p>At the end of the docs; it mentions <code>custom_filters_score</code> can take a <code>"script"</code> parameter to use instead of a <code>"boost"</code> parameter per <code>filter</code>. Best way to think of this is to calculate a number, which will be passed up to the parent query to be combined with the other sibling queries to calculate the total score for the document.</p> <h2>Custom Score Query</h2> <p><a href="http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/" rel="nofollow">Reading the docs</a> this is used when you want to customise the score from the query and change it how you wish. There is a <code>_score</code> variable available to you to use in your <code>"script"</code> which is the score of the query inside the <code>custom_score</code> query.</p> <p>Try this:</p> <pre><code>"query": { "filtered": { "query": { "custom_score": { "query": { "match_all": {} }, "script": "doc['subject_score'].value" //*see note below } }, "filter": { "and": [ { "term": { "subject": "math" } }, { "term": { "name": "user1234" } } ] } } } </code></pre> <p>*NOTE: If you wanted to you could use <code>_score</code> here. Also, I moved both your <code>"term"</code> parts to filters as any match of a term would get the same score and filters are faster.</p> <p>Good luck!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload