1

Based on text searched by user on UI, I am adding few more searchterms in the search criteria. All these works fine, however I am not able to get the proper sorted result.

My expectation would be to get the result sorting in below order:

  1. Result on top should be based on the searchterm(s) actually entered by user.
  2. Followed by result of additional searchterms I have added in my code.
Jasper Huzen
  • 1,513
  • 12
  • 26
Ravi k
  • 11
  • 1
  • 3
    welcome to SO, It would be great if you can show your code and some example documents and expected and current output, otherwise you would attract lot of downvote with this much less information. – Amit Jan 26 '20 at 11:35

2 Answers2

0

Such a sort is not possible. As per official documentation,

The sort is defined on a per field level ...

So you can't sort results by search terms.

In case of query string query you can boost terms actually entered by user, so documents with such terms will be more relevant and by default appears higher than other documents in search result. But definitely this is not sorting.

Alexey Prudnikov
  • 1,083
  • 12
  • 11
0

I think you are asking for ways to control what's called the 'relevancy' of a search result in ElasticSeach (results are ordered by relevancy by default). There are several of them, you'll have to experiment to see which one fits your needs. Each of them applies a boost-factor to the normal relevance-score of a result:

quick^2 fox

will give more relevance to documents containing 'quick'

    GET /_search 
    {
        "query": {
            "query_string" : {
                "query" : "(new york city) OR (big apple)",
                "default_field" : "content",
                "boost": 2.0
            }
        } 
    }
    {
        "query": {
            "boosting": {
                "positive": {
                    "term": {
                        "text": "apple"
                    }
                },
                "negative": {
                    "term": {
                        "text": "pie tart fruit crumble tree"
                    }
                },
                "negative_boost": 0.5
            }
        }
    }
Bart Robeyns
  • 571
  • 4
  • 14