Boosting results based on boolean field value

i found similar question http://stackoverflow.com/questions/27569686/boosting-elasticsearch-based-on-boolean-field-value, but the answer is incorrect, because it also returns all active articles which maybe to contain the word.

Hi,

can you please restate the question and the problem you are trying to solve? Looking at the question/answert you linked to I can't clearly see the problem. It would be good to re-state the full problem you are facing here in the forum.

hi,

e.g.
I have a list of article, I want to get all the article where the word "louvre" is found inside the title.

And boost the active articles before the inactive ones. I still want to be able to see both active and inactive articles which the word "louvre" is found inside the titles. But on the top of the list fist the active ones, after that inactive

So what is wrong with

{
  "query": {
    "bool": {
      "must": [
        {"match": {"title": "louvre"}}
      ],
      "should": [
        {"term": {"isActive": {"value": true}}}
      ]
    }
  }
}

I'd say this is doing what you want. If not, can you please state whats missing?

which i mentioned above, the query also returns any active articles and not looks to the title, the word contain in the title or not. it's just like title.contains("louvre") OR isActive === true

i want that it returns only articles which contain the word on the title, not just active articles.

This is a surprising result. Can you please provide a minimum reproduction including:

Create index with mapping

Index test documents with just title and value fields

Send search query

Show resulting document which doesn't have "louvre" in the title field.

You can apply a custom scorer, with some caveats:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html

Since Lucene scores are only relevant inside each individual query and are
only meant to order documents, there is no indication about what the
eventual score will be. After profiling your existing queries, determine
what you maximum score tends to be, and use this value as the floor for a
boost. Inside a function score query, simply add this boost value to
document that satisfy your requirements (active=true). In pseudo-code, it
would be something like "script" : doc[active']==true ? _score + 1000 :
_score"

Ivan