# Not finding wanted result in query string

**URL:** <https://discuss.elastic.co/t/not-finding-wanted-result-in-query-string/152020>\
**Category:** Elasticsearch\
**Created:** [October 11, 2018, 9:26am UTC](https://discuss.elastic.co/t/not-finding-wanted-result-in-query-string/152020 "2018-10-11T09:26:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon99430464](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@anon99430464](https://discuss.elastic.co/u/anon99430464)\
**Post date:** [October 11, 2018, 9:26am UTC](https://discuss.elastic.co/t/not-finding-wanted-result-in-query-string/152020/1 "2018-10-11T09:26:08Z")

</div>

Hello

We have an Elasticsearch 5.5 setup. We use nest to perform our queries through C#.

When executing the following query:

> ```
> {
> "query": {
> "bool": {
> "must": [
> {
> "query_string": {
> "query": "00917751"
> }
> }
> ]
> }
> }
> }
> 
> ```

We get the desired result: one result with that the number as identifier.

When executing the query:

> ```
> {
> "query": {
> "bool": {
> "must": [
> {
> "query_string": {
> "query": "917751"
> }
> }
> ]
> }
> }
> }
> 
> ```

We get no results.

The value we are searching for is in the field searchIndentifier, and has the value "1-00917751".

We have a custom analyzer called "final"

> .Custom("final", cu =\> cu  
> .Tokenizer("keyword").Filters(new List() { "lowercase" }))

The field searchIndentifier has no custom analyzer set on it. I tried adding the whitespace tokenizer in it but that made no difference.

Another field called "searchObjectNo" does work, when I try to search for the value "S328-25" with the query "S328". These fields are exactly the same.

Any ideas here?

Another question:  
When executing the query

> ```
> {
> "query": {
> "bool": {
> "must": [
> {
> "query_string": {
> "query": "1-00917751"
> }
> }
> ]
> }
> }
> }
> 
> ```

we get a lot of results. I would like this to return only 1 result. How would we accomplish this?

Thank you  
Schoof

Settings and mapping: [https://jsonblob.com/9dbf33f6-cd3e-11e8-8f17-c9de91b6f9d1](https://jsonblob.com/9dbf33f6-cd3e-11e8-8f17-c9de91b6f9d1)

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 15, 2018, 11:22am UTC](https://discuss.elastic.co/t/not-finding-wanted-result-in-query-string/152020/2 "2018-10-15T11:22:14Z")

</div>

You might want to take a look at the [analyze API](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/indices-analyze.html) to understand tokenization a bit better. I would also recommend using the `match` query instead of the `query_string` one if possible, as it takes field mappings into account.

---

<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 12, 2018, 11:22am UTC](https://discuss.elastic.co/t/not-finding-wanted-result-in-query-string/152020/3 "2018-11-12T11:22:23Z")

</div>

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