Building a Basic Query That Orders Results

Hello,

As a newbie, I'm trying to build a compound query for my NodeJS/Express web app. All I need is to give priority to phrases first in the search results if they exist... For example let's search for "customers are" phrase. Results should look like that:

  1. Our customers are resilient.
  2. It is always our intention that customers are satisfied with everything they buy from us.
  3. Customers who are served well become repeat customers who purchase more.
  4. Increasing number of customers who give a five star review are brilliant!

Seems like my bool query works well to achieve the results above. Here is my query:

{
    bool: {
      must: {
        match: {
          sentence: {
            query: 'customers are',
            fuzziness: 'AUTO',
            operator: 'AND',
          },
        },
      },

      should: {
        match_phrase_prefix: {
          sentence: {
            query: 'customers are',
          },
        },
      },
    },
  }

I want to add more searching features for my app.

A) When users search for "cusotmers are" instead of "customers are" with a simple typo, results look weird. For example:

  1. Once you’ve claimed your new-customer offer, there are plenty of brilliant existing promotions available which are available for all existing customers of Apple.
  2. New Customer Promo are giving new customers a fantastic offer for the NBA playoffs.
  3. Improve home security for cheaper insurance! Customers are more likely to get cheap home insurance if a provider considers them a ‘low-risk customer’.

(like you see, the 3rd result should actually have became the first result).

B) If there is no any a lot of "customers" keywords, it should also search for "customer" instead (Please check the 5th result below).

  1. Our customers are resilient.
  2. It is always our intention that customers are satisfied with everything they buy from us.
  3. Customers who are served well become repeat customers who purchase more.
  4. Increasing number of customers who give a five star review are brilliant!
  5. Most customer are expected to see their power restored by midnight.

Or if users search for "got tired", results related to "got tired" should appear first. And then other variations of the verb should appear. So, For example if there are no a lot of phrases starting with "got tired", then "get tired" should appear:

  1. He may have got tired of Hollywood.
  2. I might get tired of one and then I'll rotate to the next.
  3. ...

Thank you in advance!

Kind regards,
Serdar

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