# Prefix query with whitespaces

**URL:** <https://discuss.elastic.co/t/prefix-query-with-whitespaces/105864>\
**Category:** Elasticsearch\
**Created:** [October 31, 2017, 10:13am UTC](https://discuss.elastic.co/t/prefix-query-with-whitespaces/105864 "2017-10-31T10:13:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pyppe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pyppe/32/3531_2.png) [@Pyppe](https://discuss.elastic.co/u/Pyppe)\
**Post date:** [October 31, 2017, 10:13am UTC](https://discuss.elastic.co/t/prefix-query-with-whitespaces/105864/1 "2017-10-31T10:13:37Z")

</div>

Hi.

Why does the following prefix query return zero results:

```json
{
  "prefix": {
    "some_field": {
      "value": "hello wor"
    }
  }
}

```

Whereas the `simple_query_string` seems do what I want (and return the relevant results):

```json
{
  "simple_query_string": {
    "fields": ["some_field"],
    "default_operator": "and",
    "query": "(hello wor*)"
  }
}

```

Because the query is user-given, I'd really need to use the `prefix`-query, but it's not working the way I expected. Any tips, why that is?

---

<div class="post-metadata">

**Author:** ![Pyppe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pyppe/32/3531_2.png) [@Pyppe](https://discuss.elastic.co/u/Pyppe)\
**Post date:** [October 31, 2017, 10:20am UTC](https://discuss.elastic.co/t/prefix-query-with-whitespaces/105864/2 "2017-10-31T10:20:52Z")

</div>

OK, so the issue seems to be that `prefix` is term-level query. That's why the whitespace doesn't work there.

Now, I guess the alternative would be to use the [Match Phrase Prefix -query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html), but that requires fiddling with the `max_expansions` -parameter.

Isn't there a simple alternative to `simple_query_string` that could be used easily without worrying escaping user input?

---

<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:** [November 28, 2017, 10:21am UTC](https://discuss.elastic.co/t/prefix-query-with-whitespaces/105864/3 "2017-11-28T10:21:00Z")

</div>

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