Search text occurring priority

We want to show results based on word position.

e.g. Let's say we have below data in elasticsearch.

[
  {
      "name": "ANNUALS ASSORTED",
      "code": 3896,
      "color": "",
      "species": "ANNUALS"
  },
  {
      "name": "Rose RED ANNUALS",
      "code": 1,
      "color": "",
      "species": ""
  },
  {
      "name": "ANNUALS PROVEN WINNERS ASSORTED",
      "code": 3898,
      "color": "RED",
      "species": ""
  },
  {
      "name": "ANNUALS PREMIUM ASSORTED",
      "code": 3897,
      "color": "",
      "species": ""
  }
]

Now, if the user types A in the search box, first, it should return all the data with name starting with A and then return data where A is occurring on 2 or 3 words.

response:

[
  {
      "name": "ANNUALS ASSORTED",
      "code": 3896,
      "color": "",
      "species": "ANNUALS"
  },
  {
      "name": "ANNUALS PROVEN WINNERS ASSORTED",
      "code": 3898,
      "color": "RED",
      "species": ""
  },
  {
      "name": "ANNUALS PREMIUM ASSORTED",
      "code": 3897,
      "color": "",
      "species": ""
  },
   {
      "name": "Rose RED ANNUALS",
      "code": 1,
      "color": "",
      "species": ""
  }
]

After that, if user search ann pro, then it should return result as below.

response:

[
  {
      "name": "ANNUALS PROVEN WINNERS ASSORTED",
      "code": 3898,
      "color": "RED",
      "species": ""
  },
  {
      "name": "ANNUALS ASSORTED",
      "code": 3896,
      "color": "",
      "species": "ANNUALS"
  },
  {
      "name": "ANNUALS PREMIUM ASSORTED",
      "code": 3897,
      "color": "",
      "species": ""
  },
   {
      "name": "Rose RED ANNUALS",
      "code": 1,
      "color": "",
      "species": ""
  }
]

Any update on this?

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