# Not receiving correct results when searching for a phrase

**URL:** <https://discuss.elastic.co/t/not-receiving-correct-results-when-searching-for-a-phrase/63508>\
**Category:** Elasticsearch\
**Created:** [October 20, 2016, 1:28pm UTC](https://discuss.elastic.co/t/not-receiving-correct-results-when-searching-for-a-phrase/63508 "2016-10-20T13:28:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkarnecki](https://avatars.discourse-cdn.com/v4/letter/d/e480ec/32.png) [@dkarnecki](https://discuss.elastic.co/u/dkarnecki)\
**Post date:** [October 20, 2016, 1:28pm UTC](https://discuss.elastic.co/t/not-receiving-correct-results-when-searching-for-a-phrase/63508/1 "2016-10-20T13:28:04Z")

</div>

Can anyone see what is incorrect about the following command?

[http://192.168.1.162:9200/fborep/\_search?{](http://192.168.1.162:9200/fborep/_search?%7B) "query":{"bool": {"must": {"wildcard": {"DESC":"_post traumatic stress disorder_"}}}}}&size=100&pretty&explain

The above command returns results when submitted from a Phython program as follows:  
elastic\_query = es.search(index='fborep',body={"size":1000,"query":{"bool":{"must":[{"wildcard":{"DESC":"_post traumatic stress disorder_"}}]}}})

When the browser command is run it returns size= records from the database but not any that contain "post traumatic stress disorder" in the DESC field.

Can anyone see anything incorrect with my syntax?

Thanks,  
Dave K

---

<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:** [October 20, 2016, 2:10pm UTC](https://discuss.elastic.co/t/not-receiving-correct-results-when-searching-for-a-phrase/63508/2 "2016-10-20T14:10:20Z")

</div>

Your first query request:

```json
http://192.168.1.162:9200/fborep/_search?{ "query":{"bool": {"must": {"wildcard": {"DESC":"post traumatic stress disorder"}}}}}&size=100&pretty&explain

```

Is not valid syntax. You cannot specify JSON-style searches through the URI. That's limited to simple queries like:

```json
http://192.168.1.162:9200/fborep/_search?q=foo&size=100&pretty&explain

```

If you want to execute JSON DSL queries, you have to send it as the body of the HTTP request. From the command line using curl for example:

```json
curl -XGET "http://192.168.1.162:9200/fborep/_search?size=100&pretty&explain" -d '
{
  "query":{
    "bool":{
      "must":{
        "wildcard":{
          "DESC":"post traumatic stress disorder"
        }
      }
    }
  }
}'

```

The reason you're seeing all the results is because Elasticsearch didn't know what to do with the invalid search request, so it just executed a "Match Everything" search, which returns all your records 🙂

I'd recommend starting at the beginning of the [Definitive Guide](https://www.elastic.co/guide/en/elasticsearch/guide/2.x/_search_lite.html) and working through some of the intro chapters about search, it'll help a bunch with understanding how ES works 🙂

---

<div class="post-metadata">

**Author:** ![dkarnecki](https://avatars.discourse-cdn.com/v4/letter/d/e480ec/32.png) [@dkarnecki](https://discuss.elastic.co/u/dkarnecki)\
**Post date:** [October 20, 2016, 2:57pm UTC](https://discuss.elastic.co/t/not-receiving-correct-results-when-searching-for-a-phrase/63508/3 "2016-10-20T14:57:12Z")

</div>

Hi Zachary,

Thanks for the reply.

We were using a different query as follows:

[http://192.168.1.162:9200/fbo\_update/\_search?pretty&size=200&](http://192.168.1.162:9200/fbo_update/_search?pretty&size=200&){"query":{"wildcard":{"tags":"_post traumatic stress disorder_"}}}

and that runs correctly, giving correct results.

Isn’t this also a JSON body search? I do seem to remember reading somewhere that one could do this.  
We were wanting to submit url queries directly to the browser via C# code and that has been successful with the above query.

Thanks  
Dave K

---

<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:** [October 20, 2016, 4:08pm UTC](https://discuss.elastic.co/t/not-receiving-correct-results-when-searching-for-a-phrase/63508/4 "2016-10-20T16:08:31Z")

</div>

Yeah, that's not valid either. See [URI Search](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-uri-request.html) for details.

At one point in the distant past, you could URLencode the JSON and put it in a "source" param, but I'm not sure if this is supported anymore. And it's bad practice, since JSON DSL queries can get quite long but URIs have a fixed length limit

e.g. this used to work at some point:

```auto
ttp://localhost:9200/app/users/_search?source=%7b%22query%22%3a+%7b%22term%22%3a+%7b%22email%22%3a%22foo%40gmail.com%22%7d%7d%7d

```

---

<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:** [October 20, 2016, 4:09pm UTC](https://discuss.elastic.co/t/not-receiving-correct-results-when-searching-for-a-phrase/63508/5 "2016-10-20T16:09:29Z")

</div>

To clarify, you need to put the JSON in the HTTP request body, which means you can't execute it directly from the browser's URL bar. You'll need something like Sense, Postman extension, curl, etc which can send HTTP requests with bodies

---

<div class="post-metadata">

**Author:** ![dkarnecki](https://avatars.discourse-cdn.com/v4/letter/d/e480ec/32.png) [@dkarnecki](https://discuss.elastic.co/u/dkarnecki)\
**Post date:** [October 20, 2016, 4:28pm UTC](https://discuss.elastic.co/t/not-receiving-correct-results-when-searching-for-a-phrase/63508/6 "2016-10-20T16:28:36Z")

</div>

Thanks again Zachary,

The query I sent to you has been working from both the url directly and also from our logic that places it into the  
body before submitting it. I use the url directly to debug my queries before I place them into code but it sounds like  
this isn’t a very good idea from what you say regardless that it has “worked so far”. It won’t some day.

I’ll have to go back and debug from my code for now.

Thanks  
Dave K

![](https://us1.discourse-cdn.com/elastic/original/2X/6/64f616983d5e1c5697da3e3dc3eb37d7d031eebf.jpg)

---

<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, 10:10pm UTC](https://discuss.elastic.co/t/not-receiving-correct-results-when-searching-for-a-phrase/63508/7 "2017-07-05T22:10:45Z")

</div>


