Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understood you correctly you would like to use elasticsearch scoring if subject is not math and you would like to use custom scoring with subject is math. If you are using Elasticsearch v0.90.4 or higher, it can be achieved using new <code>function_score</code> query:</p> <pre><code>{ "query": { "function_score": { "query": { "term": { "name": "user1234" } }, "functions": [{ "filter": { "term": { "subject": "math" } }, "script_score": { "script": "doc[\"subject_score\"].value" } }, { "boost_factor": 0 }], "score_mode": "first", "boost_mode": "sum" } } } </code></pre> <p>Prior to v0.90.4 you would have to resort to using combination of <code>custom_score</code> and <code>custom_filters_score</code>:</p> <pre><code>{ "query": { "custom_score": { "query": { "custom_filters_score": { "query": { "term": { "name": "user1234" } }, "filters": [{ "filter": { "term": { "subject": "math" } }, "script": "-1.0" }] } }, "script": "_score &lt; 0.0 ? _score * -1.0 + doc[\"subject_score\"].value : _score" } } } </code></pre> <p>or as @javanna suggested, use multiple custom_score queries combined together by bool query: </p> <pre><code>{ "query": { "bool": { "disable_coord": true, "should": [{ "filtered": { "query": { "term": { "name": "user1234" } }, "filter": { "bool": { "must_not": [{ "term": { "subject": "math" } }] } } } }, { "filtered": { "query": { "custom_score": { "query": { "term": { "name": "user1234" } }, "script": "doc['subject_score'].value" } }, "filter": { "term": { "subject": "math" } } } }] } } } </code></pre>
 

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