Conditional sorting of hits

I've a index with road names. My settings look like this:

{
  "settings": {
    "max_ngram_diff": 20,
    "analysis": {
      "analyzer": {
        "str_search_analyzer": {
          "type": "custom",
          "tokenizer": "whitespace",
          "filter": [
            "lowercase"
          ]
        },
        "str_index_analyzer": {
          "type": "custom",
          "tokenizer": "whitespace",
          "filter": [
            "lowercase",
            "substring"
          ]
        }
      },
      "filter": {
        "substring": {
          "type": "edgeNGram",
          "min_gram": 1,
          "max_gram": 255
        }
      }
    }
  }
}

In the index I've strings like this:

  1. Foo Road
  2. Foo Bar Road
  3. Bar Road

So when I search for 'Bar' I get #2 and #3 as hits. This is expected.

But I would like to control the order of the hits. In this case I would like to have #3 as first hit, because the string starts with the search term.

Is it possible to sort hits as I want?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.