# Query string returns 0 hits

**URL:** <https://discuss.elastic.co/t/query-string-returns-0-hits/172185>\
**Category:** Elasticsearch\
**Created:** [March 13, 2019, 4:41pm UTC](https://discuss.elastic.co/t/query-string-returns-0-hits/172185 "2019-03-13T16:41:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohammedEssabri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohammedessabri/32/42177_2.png) [@mohammedEssabri](https://discuss.elastic.co/u/mohammedEssabri)\
**Post date:** [March 13, 2019, 4:41pm UTC](https://discuss.elastic.co/t/query-string-returns-0-hits/172185/1 "2019-03-13T16:41:55Z")

</div>

Hi there,

I am trying to add exact matching functionality in my app, but I found some issues.

I created an index **exactmatching\_v4** in my Elasticsearch cluster ( version 1.7 ) with following mappings:

```
POST /exactmatching_v4    
    {
      "aliases": {},
      "mappings": {
        
        "document": {
          
          "properties": {
            "content": {
              "type": "string",
              "index": "not_analyzed"
            },
            "lang": {
              "type": "string",
              "index": "not_analyzed"
            },
            "path": {
              "type": "string"
            }
          }
        }
      }
    }

```

And I added the following documents

```
PUT /exactmatching/document/1
{
  "content": "do test",
  "lang": "en",
  "path": "/1"
} 

 PUT /exactmatching/document/2
    {
      "content": "the test has been done",
      "lang": "en",
      "path": "/2"
    }

 PUT /exactmatching/document/3
        {
          "content": "give me some tests",
          "lang": "en",
          "path": "/3"
        }

 PUT /exactmatching/document/4
            {
              "content": "different one",
              "lang": "en",
              "path": "/4"
            }

```

The goal is to make a search that will find to me the docs containing the exact sentence **some tests**

At the first time, I had to find all docs containing the word **test** using **query\_string** , but it doesn't give any thing.

```
{
  "query": {
    "query_string": {
      "fields": [
        "content"
      ],
      "query": "test",
      "analyze_wildcard": true
    }
  }
}

```

Please not that I added **"analyze\_wildcard": true** by following a solution proposed in the following [issue](https://discuss.elastic.co/t/query-string-query-escaping-spaces-in-v2-3/81254/2).

Thank you all.

---

<div class="post-metadata">

**Author:** ![HenningAndersen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henningandersen/32/48188_2.png) [@HenningAndersen](https://discuss.elastic.co/u/HenningAndersen)\
**Post date:** [March 14, 2019, 5:37pm UTC](https://discuss.elastic.co/t/query-string-returns-0-hits/172185/2 "2019-03-14T17:37:16Z")

</div>

Hi @mohammedEssabri,

the content field is defined as not\_analyzed and therefore only supports exact match. I believe you will need to let the field be analyzed to search for terms in it.

In order to find a specific phrase like `some tests`, you will likely need to use a phrase query, either by quoting the text you search for using `query_string` or using `match_phrase`.

---

<div class="post-metadata">

**Author:** ![mohammedEssabri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohammedessabri/32/42177_2.png) [@mohammedEssabri](https://discuss.elastic.co/u/mohammedEssabri)\
**Post date:** [March 14, 2019, 10:54pm UTC](https://discuss.elastic.co/t/query-string-returns-0-hits/172185/3 "2019-03-14T22:54:22Z")

</div>

Hi @HenningAndersen,

Yes, I'm trying to find the exact matching. I mean to find doc containing the exact phrase.

You're right, I had to use the quotes.

Hereafter is the new mapping

```
"document": {
    "properties": {
      "path": {
        "type": "string"
      },
      "lang": {
        "index": "not_analyzed",
        "type": "string"
      },
      "content": {
        "index": "not_analyzed",
        "type": "string"
      }
    }
  }

```

I removed the "not-analyzed" option.

The search query is as following:

```
{
  "query": {
    "query_string": {
      "fields": [
        "content"
      ],
      "query": "\"do thi\"",
      "analyze_wildcard": true
    }
  }
}

```

Thank you again 🙂

---

<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:** [April 11, 2019, 10:57pm UTC](https://discuss.elastic.co/t/query-string-returns-0-hits/172185/4 "2019-04-11T22:57:22Z")

</div>

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