# Weird behavior of 'query\_string' query. Possible false positive result

**URL:** <https://discuss.elastic.co/t/weird-behavior-of-query-string-query-possible-false-positive-result/33974>\
**Category:** Elasticsearch\
**Created:** [November 6, 2015, 9:50am UTC](https://discuss.elastic.co/t/weird-behavior-of-query-string-query-possible-false-positive-result/33974 "2015-11-06T09:50:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lakomkin\_Egor](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@Lakomkin\_Egor](https://discuss.elastic.co/u/Lakomkin_Egor)\
**Post date:** [November 6, 2015, 9:50am UTC](https://discuss.elastic.co/t/weird-behavior-of-query-string-query-possible-false-positive-result/33974/1 "2015-11-06T09:50:28Z")

</div>

I need to do phrase search, where I need several things:

1. the order of the words does not matter
2. I need to specify the possible gap between matched words
3. I need to consider matches with stopwords inside the phrase

I have found that 'query\_string' can deal with all of those.

The question I have is that if I have a document **"three four world that awesome those hello five"** and I would look for **"hello world"** I expect that this document won't be matched if I specify slop(or gap between matches) as 0.

I have attached script that reproduces this false positive. Script is [here](https://gist.github.com/EgorLakomkin/b72d68410e0682243cea)  
Maybe I am doing something wrong?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [November 6, 2015, 3:05pm UTC](https://discuss.elastic.co/t/weird-behavior-of-query-string-query-possible-false-positive-result/33974/2 "2015-11-06T15:05:02Z")

</div>

The query\_string syntax for phrases is to wrap the phrase in quotes. Your query is just looking for the terms individually (no phrase), which is why it's matching.

Try this instead:

```auto
"query": "\"hello world\"",

```

---

<div class="post-metadata">

**Author:** ![softwaredoug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/softwaredoug/32/22681_2.png) [@softwaredoug](https://discuss.elastic.co/u/softwaredoug)\
**Post date:** [November 7, 2015, 4:33pm UTC](https://discuss.elastic.co/t/weird-behavior-of-query-string-query-possible-false-positive-result/33974/3 "2015-11-07T16:33:28Z")

</div>

Also curious why query\_string would be what you wanted? query\_string is usually good for users that have an expectation of searching with a traditional search syntax (`title:dog AND body:cat`).

Wolud a match\_phrase query be more specific, carry fewer surprises, and be easier to tune?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [November 9, 2015, 1:58pm UTC](https://discuss.elastic.co/t/weird-behavior-of-query-string-query-possible-false-positive-result/33974/4 "2015-11-09T13:58:58Z")

</div>

> [@softwaredoug](#):
>
> Wolud a match\_phrase query be more specific, carry fewer surprises, and be easier to tune?

++

I try to avoid query\_string as much as possible myself, there are a lot of ways to trip yourself (and your users) up. Using the `match` family as much as possible tends to work better, as well as constructing more complicated queries yourself (e.g. `bool` combinations) rather than relying on the user to construct it in a single line.

---

<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:** [July 5, 2017, 11:39pm UTC](https://discuss.elastic.co/t/weird-behavior-of-query-string-query-possible-false-positive-result/33974/5 "2017-07-05T23:39:47Z")

</div>


