# Change AppSearch Query

**URL:** <https://discuss.elastic.co/t/change-appsearch-query/268413>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [March 25, 2021, 9:23pm UTC](https://discuss.elastic.co/t/change-appsearch-query/268413 "2021-03-25T21:23:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [March 25, 2021, 9:23pm UTC](https://discuss.elastic.co/t/change-appsearch-query/268413/1 "2021-03-25T21:23:35Z")

</div>

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

```auto
 {
                    "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 🙂

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

```auto
 {
                    "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

---

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [March 25, 2021, 9:55pm UTC](https://discuss.elastic.co/t/change-appsearch-query/268413/2 "2021-03-25T21:55:58Z")

</div>

I found a related topic to my issue here

> [@Filter search by score](https://discuss.elastic.co/t/filter-search-by-score/208322):
>
> I’d like to perform a search, but only get back search results that have a score greater-than 1 for instance. Is this possible?

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

---

<div class="post-metadata">

**Author:** ![Vadim\_Yakhin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vadim_yakhin/32/56723_2.png) [@Vadim\_Yakhin](https://discuss.elastic.co/u/Vadim_Yakhin)\
**Post date:** [March 26, 2021, 1:58pm UTC](https://discuss.elastic.co/t/change-appsearch-query/268413/3 "2021-03-26T13:58:58Z")

</div>

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](https://www.elastic.co/guide/en/enterprise-search/7.12/release-notes-7.12.0.html#release-notes-7-12-0-enterprise-search):

> 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](https://www.elastic.co/guide/en/enterprise-search/current/upgrading-from-enterprise-search-7-11-and-earlier.html), 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

---

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [March 26, 2021, 6:30pm UTC](https://discuss.elastic.co/t/change-appsearch-query/268413/4 "2021-03-26T18:30:23Z")

</div>

Thanks @Vadim_Yakhin for your feedback  
Appreciate

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [March 31, 2021, 8:47am UTC](https://discuss.elastic.co/t/change-appsearch-query/268413/5 "2021-03-31T08:47:24Z")

</div>

> [@ylasri](#):
>
> This typically my use case, where the ngram analyzer is bringing some inexpected facets

One [workaround](https://discuss.elastic.co/t/turn-off-irrelevant-sounds-like-search-result/251259/3) 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.

---

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [April 1, 2021, 10:45am UTC](https://discuss.elastic.co/t/change-appsearch-query/268413/6 "2021-04-01T10:45:51Z")

</div>

Many thanks @Mark_Harwood  
That's definetly a nice workaround

---

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [April 22, 2021, 9:14am UTC](https://discuss.elastic.co/t/change-appsearch-query/268413/7 "2021-04-22T09:14:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [April 22, 2021, 9:40am UTC](https://discuss.elastic.co/t/change-appsearch-query/268413/8 "2021-04-22T09:40:11Z")

</div>

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](https://github.com/elastic/ent-search/blob/076c92edb338733141df6533af6cd53fca932526/lib/query_builder/base.rb#L107) 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.

---

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [April 22, 2021, 9:58am UTC](https://discuss.elastic.co/t/change-appsearch-query/268413/9 "2021-04-22T09:58:47Z")

</div>

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"

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [April 22, 2021, 10:09am UTC](https://discuss.elastic.co/t/change-appsearch-query/268413/10 "2021-04-22T10:09:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 20, 2021, 10:10am UTC](https://discuss.elastic.co/t/change-appsearch-query/268413/11 "2021-05-20T10:10:13Z")

</div>

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