Change AppSearch Query

Hello

I am using Appsearch to power search for an application, I know that App search take care of the mapping & analyzer, and also the search query, when doing some inspection, i could see the kind of the search query sent to ES endpoint, something like this

 {
                    "multi_match": {
                      "query": "United Kingdom",
                      "minimum_should_match": "1<-1 3<49%",
                      "boost": 1,
                      "type": "cross_fields",
                      "operator": "OR",
                      "fields": [
                        "country$string^1.0",
                        "country$string.stem^0.95",
                        "country$string.prefix^0.1",
                        "country$string.joined^0.75",
                        "country$string.delimiter^0.4",
                        "name$string^1.0",
                        "name$string.stem^0.95",
                        "name$string.prefix^0.1",
                        "name$string.joined^0.75",
                        "name$string.delimiter^0.4",
                        "external_id^1.0"
                      ]
                    }
                  }

My search logic does not require searching on fields analyzed diffrently like stem, prefix, joinded, i want to search only on the basic fields like : country$string & name$string

How i can change the behavior of App search to search only on fields i want to avoid getting some noises :slight_smile:

Like if i want to ask App search to send something like this

 {
                    "multi_match": {
                      "query": "United Kingdom",
                      "minimum_should_match": "1<-1 3<49%",
                      "boost": 1,
                      "type": "cross_fields",
                      "operator": "OR",
                      "fields": [
                        "country$string^1.0",
                        "name$string^1.0"
                      ]
                    }
                  }

Thank You

I found a related topic to my issue here

This typically my use case, where the ngram analyzer is bringing some inexpected facets :slight_smile:

Hi Yassine,

I don't think there's a way to do what you described currently.

If you want to increase precision, I recommend upgrading to v7.12 if you're not already on it. Here are a couple of items from the changelog:

Enterprise Search 7.12

Improves query precision:

  • Increased query precision with fewer long-tail results.
  • Improved typo-tolerance for more resilient search.

If you decide to upgrade, make sure to follow the upgrade instructions, this release is special.

Also, we have a feature in our near-term roadmap that will allow you to improve precision even further. I cannot commit to specific timelines, though.

Hope it helps!
Vadim

1 Like

Thanks @Vadim_Yakhin for your feedback
Appreciate

1 Like

One workaround is to add any Boolean operators (AND/OR/NOT or ") to your query string.
This changes the search logic from being interpreted as a fuzzy match to exact-string matching.

1 Like

Many thanks @Mark_Harwood
That's definetly a nice workaround

1 Like

Hi @Mark_Harwood Hope you are doing and Apologize if i tag you directly
The way i used to workaround this issue by using AND and double quote is working perfect
But that disable the ability to use Synnyms in Appsearch

I will give you an example, a user search for Rome or Roma, they should bring same result
But the fact that i send "Rome", "Roma" to Appsearch API disable the usage of synonyms

Do you have any idea on how to fix this ?

Thank You

Hi Yassine,
Sorry, we'll need a member of the app-search team to respond to this question.

I'm a dev on the core elasticsearch engine and the Boolean syntax trick to removing irrelevant results is one I just came across as a casual user of app-search.

The parsing logic looks to branch hard in behaviour if any Boolean clauses are used. You can see the various places in the parser code where parsing decisions differ if the complex_query flag is set (aka when queries use Boolean syntax). Obviously synonym support is part of that differing behaviour.

This will probably need the dev team to chime in here.

But the fact that i send "Rome", "Roma" to Appsearch API disable the usage of synonyms

Does Rome OR Roma work instead? There may be something in particular about phrase queries caused by use of quotes.

Thanks @Mark_Harwood for your quick feedback

Yes, from the Appsearch API, searching with the query="Rome" OR "Roma" is working perfectly and provide exactly the desired results

But Business user are defining a set of synonyms like Rome, Roma, Italy, Italia and they would love seeing same results if a user type one these keywords

So basically to avoid ngram effects, we are sending query to appsearch using :

  • Double quotes if the query is a signe keyword, like Rome => "Rome"
  • Double quotes with AND operator if search query with multiple keywords, Like : House Roma => "House" AND "Roma"

My original workaround suggestion to make app-search run strict queries (what it internally calls "complex" queries) is to use either :

  1. any Boolean syntax (AND/OR/NOT) or
  2. a Phrase query (putting quotes around strings)

I can see you've used a mix of these strategies in search strings like "House" AND "Roma".
My suggestion is that if you lose the quotes and rely only on the AND/OR/NOT way of creating complex queries it might give different behaviour e.g.

  • instead of "House" AND "Roma" use House AND Roma
  • instead of plain "Roma" use Roma OR Roma

No guarantees it will work but the synonym problem you have might be limited to the execution of phrase queries.

1 Like

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