# Comples proximity searches using the simple\_query\_string

**URL:** <https://discuss.elastic.co/t/comples-proximity-searches-using-the-simple-query-string/114603>\
**Category:** Elasticsearch\
**Created:** [January 8, 2018, 7:41pm UTC](https://discuss.elastic.co/t/comples-proximity-searches-using-the-simple-query-string/114603 "2018-01-08T19:41:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgrishaber](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@mgrishaber](https://discuss.elastic.co/u/mgrishaber)\
**Post date:** [January 8, 2018, 7:41pm UTC](https://discuss.elastic.co/t/comples-proximity-searches-using-the-simple-query-string/114603/1 "2018-01-08T19:41:58Z")

</div>

Hello,

I am trying to use the simple\_query\_string to perform a proximity search using the ~ operator.  
Something like the following works fine.

"simple\_query\_string": {"query": ""Arizona Diamondbacks"~8", "default\_operator": "AND"}

However I need to be able to define the words being searched for as a complex expression such as the following.

"simple\_query\_string": {"query": ""Arizona (Brewers | Diamondbacks)"~8", "default\_operator": "AND"}

The expression could get much more complex than this, with the proximity terms becoming recursive AND/OR type algebraic expressions.

Is this achievable using the simple\_query\_string, or should I be looking elsewhere?

Thanks

---

<div class="post-metadata">

**Author:** ![luiz.santos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luiz.santos/32/24664_2.png) [@luiz.santos](https://discuss.elastic.co/u/luiz.santos)\
**Post date:** [January 9, 2018, 2:00pm UTC](https://discuss.elastic.co/t/comples-proximity-searches-using-the-simple-query-string/114603/2 "2018-01-09T14:00:37Z")

</div>

Hi @mgrishaber,

For complex logic with lots AND/ORs I think it's easier to use a boolean filter with fuzziness parameter:

```
GET my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "field1": {
              "query": "univers",
              "fuzziness": "8"
            }
          }
        }
      ],
      "should": [
        {
          "match": {
            "field1": {
              "query": "universe",
              "fuzziness": "8"
            }
          }
        },
        {
          "match": {
            "field1": {
              "query": "universo",
              "fuzziness": "8"
            }
          }
        }
      ]
    }
  }
}

```

Maybe it can help you.

Cheers,  
LG

---

<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:** [February 6, 2018, 2:01pm UTC](https://discuss.elastic.co/t/comples-proximity-searches-using-the-simple-query-string/114603/3 "2018-02-06T14:01:05Z")

</div>

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