# Problem with searching via json api

**URL:** <https://discuss.elastic.co/t/problem-with-searching-via-json-api/4054>\
**Category:** Elasticsearch\
**Created:** [March 8, 2011, 12:27am UTC](https://discuss.elastic.co/t/problem-with-searching-via-json-api/4054 "2011-03-08T00:27:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Reelsen](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@Alexander\_Reelsen](https://discuss.elastic.co/u/Alexander_Reelsen)\
**Post date:** [March 8, 2011, 12:27am UTC](https://discuss.elastic.co/t/problem-with-searching-via-json-api/4054/1 "2011-03-08T00:27:47Z")

</div>

Hi there,

I have a problem with elastic search when using the json query api  
(using terms)

The following query works:

# curl -XPOST

'localhost:9200/example-app/car/\_search?q=brand:Audi&pretty=true'

{  
"took" : 2,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 1.4054651,  
"hits" : [ {  
"\_index" : "example-app",  
"\_type" : "car",  
"\_id" : "220",  
"\_score" : 1.4054651, "\_source" :  
{"brand":"Audi","type":"A5","price":60000}  
} ]  
}  
}

This query does not work:

# curl -XPOST 'localhost:9200/example-app/car/\_search?pretty=true' -d

'  
{ "query": { "term" : { "brand" : "Audi" }}}'

{  
"took" : 1,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}

I am supposing that I simply misunderstood the basic query  
capabilities. There are no exceptions in the logs either, so I think  
it must be some beginners mistake.

Any help is greatly appreciated!

--Alexander

---

<div class="post-metadata">

**Author:** ![IvanBrusic](https://avatars.discourse-cdn.com/v4/letter/i/ecae2f/32.png) [@IvanBrusic](https://discuss.elastic.co/u/IvanBrusic)\
**Post date:** [March 8, 2011, 2:54am UTC](https://discuss.elastic.co/t/problem-with-searching-via-json-api/4054/2 "2011-03-08T02:54:18Z")

</div>

Queries made using the \_search?q= syntax will be analyzed by the  
default analyzer before searching. Term queries using the DSL are NOT  
analyzed. I assume that the "brand" field is analyzed and therefore  
the query DSL is not working. Try searching for lower "audi".

Ivan

On Mar 7, 7:27 pm, Alexander Reelsen  
[alexander.reel...@googlemail.com](mailto:alexander.reel...@googlemail.com) wrote:

> Hi there,
> 
> I have a problem with Elasticsearch when using the json query api  
> (using terms)
> 
> The following query works:
> 
> # curl -XPOST
> 
> 'localhost:9200/example-app/car/\_search?q=brand:Audi&pretty=true'
> 
> {  
> "took" : 2,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 1.4054651,  
> "hits" : [ {  
> "\_index" : "example-app",  
> "\_type" : "car",  
> "\_id" : "220",  
> "\_score" : 1.4054651, "\_source" :  
> {"brand":"Audi","type":"A5","price":60000}  
> } ]  
> }
> 
> }
> 
> This query does not work:
> 
> # curl -XPOST 'localhost:9200/example-app/car/\_search?pretty=true' -d
> 
> '  
> { "query": { "term" : { "brand" : "Audi" }}}'
> 
> {  
> "took" : 1,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }
> 
> }
> 
> I am supposing that I simply misunderstood the basic query  
> capabilities. There are no exceptions in the logs either, so I think  
> it must be some beginners mistake.
> 
> Any help is greatly appreciated!
> 
> --Alexander

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 8, 2011, 6:48am UTC](https://discuss.elastic.co/t/problem-with-searching-via-json-api/4054/3 "2011-03-08T06:48:57Z")

</div>

Another option is to use the query\_string or field query in the query DSL, instead of the term query.  
On Tuesday, March 8, 2011 at 4:54 AM, Ivan Brusic wrote:

> Queries made using the \_search?q= syntax will be analyzed by the  
> default analyzer before searching. Term queries using the DSL are NOT  
> analyzed. I assume that the "brand" field is analyzed and therefore  
> the query DSL is not working. Try searching for lower "audi".
> 
> Ivan
> 
> On Mar 7, 7:27 pm, Alexander Reelsen  
> [alexander.reel...@googlemail.com](mailto:alexander.reel...@googlemail.com) wrote:
> 
> > Hi there,
> > 
> > I have a problem with Elasticsearch when using the json query api  
> > (using terms)
> > 
> > The following query works:
> > 
> > # curl -XPOST
> > 
> > 'localhost:9200/example-app/car/\_search?q=brand:Audi&pretty=true'
> > 
> > {  
> > "took" : 2,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 1,  
> > "max\_score" : 1.4054651,  
> > "hits" : [ {  
> > "\_index" : "example-app",  
> > "\_type" : "car",  
> > "\_id" : "220",  
> > "\_score" : 1.4054651, "\_source" :  
> > {"brand":"Audi","type":"A5","price":60000}  
> > } ]  
> > }
> > 
> > }
> > 
> > This query does not work:
> > 
> > # curl -XPOST 'localhost:9200/example-app/car/\_search?pretty=true' -d
> > 
> > '  
> > { "query": { "term" : { "brand" : "Audi" }}}'
> > 
> > {  
> > "took" : 1,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }
> > 
> > }
> > 
> > I am supposing that I simply misunderstood the basic query  
> > capabilities. There are no exceptions in the logs either, so I think  
> > it must be some beginners mistake.
> > 
> > Any help is greatly appreciated!
> > 
> > --Alexander

---

<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 6, 2017, 4:10am UTC](https://discuss.elastic.co/t/problem-with-searching-via-json-api/4054/4 "2017-07-06T04:10:34Z")

</div>


