# Query not retuning document

**URL:** <https://discuss.elastic.co/t/query-not-retuning-document/3973>\
**Category:** Elasticsearch\
**Created:** [February 24, 2011, 5:37pm UTC](https://discuss.elastic.co/t/query-not-retuning-document/3973 "2011-02-24T17:37:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sky\_Stebnicki1](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Sky\_Stebnicki1](https://discuss.elastic.co/u/Sky_Stebnicki1)\
**Post date:** [February 24, 2011, 5:37pm UTC](https://discuss.elastic.co/t/query-not-retuning-document/3973/1 "2011-02-24T17:37:42Z")

</div>

Hi everyone, I cannot figure out why the following search does not  
work. If you could help get me pointed in the right direction on this  
issue I would greatly appreciate it.

Here is the mapping (I have omitted non-related properties for  
simplicity):

curl -GET [http://localhost:9200/ant\_demo/email\_thread/\_mapping?pretty=true](http://localhost:9200/ant_demo/email_thread/_mapping?pretty=true)  
{  
"ant\_demo" : {  
"id" : {  
"type" : "long"  
},  
"owner\_id" : {  
"type" : "string"  
}  
}  
}  
}  
}

Pulling a record by id so we know it exists:

curl -XGET [http://localhost:9200/an\_demo/contact\_personal/3](http://localhost:9200/an_demo/contact_personal/3)  
{  
"\_index":"ant\_demo",  
"\_type":"contact\_personal",  
"\_id":"3","\_version":2,  
"\_source" :  
{  
"f\_deleted":"false",  
"id":"3",  
"user\_id":"2"  
}  
}

Try to query based on user\_id:

curl -XGET http://local\_demo/contact\_personal/\_search?pretty=true -d '  
{  
"query" :  
{  
"query\_string" :  
{  
"query" : "user\_id:2"  
}  
}  
}  
';

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

I also tried:

curl -XGET [http://localhost:9200/ant\_demo/contact\_personal/\_search?q=user\_id:2](http://localhost:9200/ant_demo/contact_personal/_search?q=user_id:2)

But got 0 hits. Why is this?

---

<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:** [February 25, 2011, 1:05am UTC](https://discuss.elastic.co/t/query-not-retuning-document/3973/2 "2011-02-25T01:05:31Z")

</div>

Can you generate a curl recreation with the indexing part? Check [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help).  
On Thursday, February 24, 2011 at 7:37 PM, SkyStebnicki wrote:

> Hi everyone, I cannot figure out why the following search does not  
> work. If you could help get me pointed in the right direction on this  
> issue I would greatly appreciate it.
> 
> Here is the mapping (I have omitted non-related properties for  
> simplicity):
> 
> curl -GET [http://localhost:9200/ant\_demo/email\_thread/\_mapping?pretty=true](http://localhost:9200/ant_demo/email_thread/_mapping?pretty=true)  
> {  
> "ant\_demo" : {  
> "id" : {  
> "type" : "long"  
> },  
> "owner\_id" : {  
> "type" : "string"  
> }  
> }  
> }  
> }  
> }
> 
> Pulling a record by id so we know it exists:
> 
> curl -XGET [http://localhost:9200/an\_demo/contact\_personal/3](http://localhost:9200/an_demo/contact_personal/3)  
> {  
> "\_index":"ant\_demo",  
> "\_type":"contact\_personal",  
> "\_id":"3","\_version":2,  
> "\_source" :  
> {  
> "f\_deleted":"false",  
> "id":"3",  
> "user\_id":"2"  
> }  
> }
> 
> Try to query based on user\_id:
> 
> curl -XGET http://local\_demo/contact\_personal/\_search?pretty=true -d '  
> {  
> "query" :  
> {  
> "query\_string" :  
> {  
> "query" : "user\_id:2"  
> }  
> }  
> }  
> ';
> 
> The results:  
> {  
> "took" : 5,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }
> 
> I also tried:
> 
> curl -XGET [http://localhost:9200/ant\_demo/contact\_personal/\_search?q=user\_id:2](http://localhost:9200/ant_demo/contact_personal/_search?q=user_id:2)
> 
> But got 0 hits. Why is this?

---

<div class="post-metadata">

**Author:** ![Sky\_Stebnicki1](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Sky\_Stebnicki1](https://discuss.elastic.co/u/Sky_Stebnicki1)\
**Post date:** [February 25, 2011, 7:51am UTC](https://discuss.elastic.co/t/query-not-retuning-document/3973/3 "2011-02-25T07:51:08Z")

</div>

Yeah that's kind of a problem. This is a large index being created by  
our web application through a PHP interface. It's difficult to  
reproduce with a few simple commands in CURL because we cannot  
replicate the behaviour. That's why I was hoping there was some other  
way to determine why the document was not found even though it clearly  
exists in the index. I can continue testing to try and figure out  
exactly why this happened and how to reproduce it.

On Feb 24, 5:05 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Can you generate a curl recreation with the indexing part? Checkhttp://www.elasticsearch.org/help.
> 
> On Thursday, February 24, 2011 at 7:37 PM, SkyStebnicki wrote:
> 
> > Hi everyone, I cannot figure out why the following search does not  
> > work. If you could help get me pointed in the right direction on this  
> > issue I would greatly appreciate it.
> 
> > Here is the mapping (I have omitted non-related properties for  
> > simplicity):
> 
> > curl -GEThttp://localhost:9200/ant\_demo/email\_thread/\_mapping?pretty=true  
> > {  
> > "ant\_demo" : {  
> > "id" : {  
> > "type" : "long"  
> > },  
> > "owner\_id" : {  
> > "type" : "string"  
> > }  
> > }  
> > }  
> > }  
> > }
> 
> > Pulling a record by id so we know it exists:
> 
> > curl -XGEThttp://localhost:9200/an\_demo/contact\_personal/3  
> > {  
> > "\_index":"ant\_demo",  
> > "\_type":"contact\_personal",  
> > "\_id":"3","\_version":2,  
> > "\_source" :  
> > {  
> > "f\_deleted":"false",  
> > "id":"3",  
> > "user\_id":"2"  
> > }  
> > }
> 
> > Try to query based on user\_id:
> 
> > curl -XGEThttp://local\_demo/contact\_personal/\_search?pretty=true-d '  
> > {  
> > "query" :  
> > {  
> > "query\_string" :  
> > {  
> > "query" : "user\_id:2"  
> > }  
> > }  
> > }  
> > ';
> 
> > The results:  
> > {  
> > "took" : 5,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }  
> > }
> 
> > I also tried:
> 
> > curl -XGEThttp://localhost:9200/ant\_demo/contact\_personal/\_search?q=user\_id:2
> 
> > But got 0 hits. Why is this?

---

<div class="post-metadata">

**Author:** ![Sky\_Stebnicki1](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Sky\_Stebnicki1](https://discuss.elastic.co/u/Sky_Stebnicki1)\
**Post date:** [February 25, 2011, 4:36pm UTC](https://discuss.elastic.co/t/query-not-retuning-document/3973/4 "2011-02-25T16:36:55Z")

</div>

I deleted the type, then reindexed all the documents for that type  
with the exact same data. The query now works? Interesting. I wonder  
if it has anything to do with the types. Is there a way to turn off  
the automatic schema mapping so I can force a manual map at all times?

Sky

On Feb 24, 11:51 pm, SkyStebnicki [sky.stebni...@gmail.com](mailto:sky.stebni...@gmail.com) wrote:

> Yeah that's kind of a problem. This is a large index being created by  
> our web application through a PHP interface. It's difficult to  
> reproduce with a few simple commands in CURL because we cannot  
> replicate the behaviour. That's why I was hoping there was some other  
> way to determine why the document was not found even though it clearly  
> exists in the index. I can continue testing to try and figure out  
> exactly why this happened and how to reproduce it.
> 
> On Feb 24, 5:05 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > Can you generate a curl recreation with the indexing part? Checkhttp://www.elasticsearch.org/help.
> 
> > On Thursday, February 24, 2011 at 7:37 PM, SkyStebnicki wrote:
> > 
> > > Hi everyone, I cannot figure out why the following search does not  
> > > work. If you could help get me pointed in the right direction on this  
> > > issue I would greatly appreciate it.
> 
> > > Here is the mapping (I have omitted non-related properties for  
> > > simplicity):
> 
> > > curl -GEThttp://localhost:9200/ant\_demo/email\_thread/\_mapping?pretty=true  
> > > {  
> > > "ant\_demo" : {  
> > > "id" : {  
> > > "type" : "long"  
> > > },  
> > > "owner\_id" : {  
> > > "type" : "string"  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> 
> > > Pulling a record by id so we know it exists:
> 
> > > curl -XGEThttp://localhost:9200/an\_demo/contact\_personal/3  
> > > {  
> > > "\_index":"ant\_demo",  
> > > "\_type":"contact\_personal",  
> > > "\_id":"3","\_version":2,  
> > > "\_source" :  
> > > {  
> > > "f\_deleted":"false",  
> > > "id":"3",  
> > > "user\_id":"2"  
> > > }  
> > > }
> 
> > > Try to query based on user\_id:
> 
> > > curl -XGEThttp://local\_demo/contact\_personal/\_search?pretty=true-d'  
> > > {  
> > > "query" :  
> > > {  
> > > "query\_string" :  
> > > {  
> > > "query" : "user\_id:2"  
> > > }  
> > > }  
> > > }  
> > > ';
> 
> > > The results:  
> > > {  
> > > "took" : 5,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 5,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 0,  
> > > "max\_score" : null,  
> > > "hits" :   
> > > }  
> > > }
> 
> > > I also tried:
> 
> > > curl -XGEThttp://localhost:9200/ant\_demo/contact\_personal/\_search?q=user\_id:2
> 
> > > But got 0 hits. Why is this?

---

<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:** [February 25, 2011, 7:58pm UTC](https://discuss.elastic.co/t/query-not-retuning-document/3973/5 "2011-02-25T19:58:30Z")

</div>

Yes, in 0.15, you can set in the mapping dynamic set to strict: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html).  
On Friday, February 25, 2011 at 6:36 PM, SkyStebnicki wrote:

> I deleted the type, then reindexed all the documents for that type  
> with the exact same data. The query now works? Interesting. I wonder  
> if it has anything to do with the types. Is there a way to turn off  
> the automatic schema mapping so I can force a manual map at all times?
> 
> Sky
> 
> On Feb 24, 11:51 pm, SkyStebnicki [sky.stebni...@gmail.com](mailto:sky.stebni...@gmail.com) wrote:
> 
> > Yeah that's kind of a problem. This is a large index being created by  
> > our web application through a PHP interface. It's difficult to  
> > reproduce with a few simple commands in CURL because we cannot  
> > replicate the behaviour. That's why I was hoping there was some other  
> > way to determine why the document was not found even though it clearly  
> > exists in the index. I can continue testing to try and figure out  
> > exactly why this happened and how to reproduce it.
> > 
> > On Feb 24, 5:05 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > 
> > > Can you generate a curl recreation with the indexing part? Checkhttp://www.elasticsearch.org/help.
> > 
> > > On Thursday, February 24, 2011 at 7:37 PM, SkyStebnicki wrote:
> > > 
> > > > Hi everyone, I cannot figure out why the following search does not  
> > > > work. If you could help get me pointed in the right direction on this  
> > > > issue I would greatly appreciate it.
> > 
> > > > Here is the mapping (I have omitted non-related properties for  
> > > > simplicity):
> > 
> > > > curl -GEThttp://localhost:9200/ant\_demo/email\_thread/\_mapping?pretty=true  
> > > > {  
> > > > "ant\_demo" : {  
> > > > "id" : {  
> > > > "type" : "long"  
> > > > },  
> > > > "owner\_id" : {  
> > > > "type" : "string"  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > 
> > > > Pulling a record by id so we know it exists:
> > 
> > > > curl -XGEThttp://localhost:9200/an\_demo/contact\_personal/3  
> > > > {  
> > > > "\_index":"ant\_demo",  
> > > > "\_type":"contact\_personal",  
> > > > "\_id":"3","\_version":2,  
> > > > "\_source" :  
> > > > {  
> > > > "f\_deleted":"false",  
> > > > "id":"3",  
> > > > "user\_id":"2"  
> > > > }  
> > > > }
> > 
> > > > Try to query based on user\_id:
> > 
> > > > curl -XGEThttp://local\_demo/contact\_personal/\_search?pretty=true-d'  
> > > > {  
> > > > "query" :  
> > > > {  
> > > > "query\_string" :  
> > > > {  
> > > > "query" : "user\_id:2"  
> > > > }  
> > > > }  
> > > > }  
> > > > ';
> > 
> > > > The results:  
> > > > {  
> > > > "took" : 5,  
> > > > "timed\_out" : false,  
> > > > "\_shards" : {  
> > > > "total" : 5,  
> > > > "successful" : 5,  
> > > > "failed" : 0  
> > > > },  
> > > > "hits" : {  
> > > > "total" : 0,  
> > > > "max\_score" : null,  
> > > > "hits" :   
> > > > }  
> > > > }
> > 
> > > > I also tried:
> > 
> > > > curl -XGEThttp://localhost:9200/ant\_demo/contact\_personal/\_search?q=user\_id:2
> > 
> > > > But got 0 hits. Why is this?

---

<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:11am UTC](https://discuss.elastic.co/t/query-not-retuning-document/3973/6 "2017-07-06T04:11:27Z")

</div>


