# Query search yielding unexpected results

**URL:** <https://discuss.elastic.co/t/query-search-yielding-unexpected-results/3118>\
**Category:** Elasticsearch\
**Created:** [July 19, 2010, 1:09pm UTC](https://discuss.elastic.co/t/query-search-yielding-unexpected-results/3118 "2010-07-19T13:09:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajgamer](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@ajgamer](https://discuss.elastic.co/u/ajgamer)\
**Post date:** [July 19, 2010, 1:09pm UTC](https://discuss.elastic.co/t/query-search-yielding-unexpected-results/3118/1 "2010-07-19T13:09:33Z")

</div>

Hi,

I am working with elasticsearch version 0.7 and have encountered my  
first roadblock. I have two mappings named detail and master. The  
schema for detail is as follows :  
{  
"properties": {

```
        \"userid\": {
            \"type\": \"string\",
            \"index_name\": \"userid\",
            \"index\": \"not_analyzed\",
            \"store\": \"no\",
            \"term_vector\": \"no\",
            \"boost\": 1.0,
            \"omit_norms\": true,
            \"omit_term_freq_and_positions\": true
        },
    }
}

```

What i'm trying to do here is search on the userid field using the  
query params as  
http://\*\*_. **.**._:9200/tournament/detail/\_search?q=userid:potter  
and it returns the data

# {

```
* _index: "tournament"
* _type: "detail"
* _id: "22|potter"
*
  -
  _source: {
      o tournamentid: 22
      o userid: "potter"
      o date: "2008-06-16T18:30:00.000Z"
      o score: 276.62
      o tries: 1
      o gameid: 32
      o gamename: "Caravan Toss"
      o status: 3
      o scoretype: 3
      o result: 1
  }

```

}

# 

# 

- 

{

```
* _index: "tournament"
* _type: "detail"
* _id: "593|harry_potter"
*
  -
  _source: {
      o tournamentid: 593
      o userid: "harry_potter"
      o date: "2009-04-01T18:30:00.000Z"
      o score: 212
      o tries: 1
      o gameid: 732
      o gamename: "Trick Blast Billiards"
      o status: 3
      o scoretype: 1
      o result: 0
  }

```

}

# 

- 

{

```
* _index: "tournament"
* _type: "detail"
* _id: "602|harry_potter"
*
  -
  _source: {
      o tournamentid: 602
      o userid: "harry_potter"
      o date: "2009-04-01T18:30:00.000Z"
      o score: 190
      o tries: 2
      o gameid: 16
      o gamename: "Ski Run"
      o status: 3
      o scoretype: 1
      o result: 0
  }

```

}  
BTW this was when the schema was set to "index": "analyzed" for the  
userid field.

But when i changed the index field to not\_analysed i only got the  
results for potter. But when i queried for the field  
harry\_potter(http://\*\*\*. **_._.** :9200/tournament/detail/\_search?  
q=userid:harry\_potter) i am unable to get the data for it even though  
its there and i can see the data when i use a wild card like  
\*harry\_potter.

And since I've changed the omit\_norms and omit\_term\_freq\_and\_positions  
to true but to no effect.

What changes do i need to make in my schema to see the desired results.

---

<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:** [July 19, 2010, 5:58pm UTC](https://discuss.elastic.co/t/query-search-yielding-unexpected-results/3118/2 "2010-07-19T17:58:51Z")

</div>

Before version 0.9 (which is master now), not\_analyzed fields were still  
tokenized when used in a query string explicitly. You should define the  
analyzer to be "keyword" (sounds strange, I know) even when its not  
analyzed. This is done for by default in upcoming 0.9.

-shay.banon

On Mon, Jul 19, 2010 at 4:09 PM, ajgamer [abie.joseph14@gmail.com](mailto:abie.joseph14@gmail.com) wrote:

> Hi,
> 
> I am working with elasticsearch version 0.7 and have encountered my  
> first roadblock. I have two mappings named detail and master. The  
> schema for detail is as follows :  
> {  
> "properties": {
> 
> ```
> \"userid\": {
> \"type\": \"string\",
> \"index_name\": \"userid\",
> \"index\": \"not_analyzed\",
> \"store\": \"no\",
> \"term_vector\": \"no\",
> \"boost\": 1.0,
> \"omit_norms\": true,
> \"omit_term_freq_and_positions\": true
> },
> }
> 
> ```
> 
> }
> 
> What i'm trying to do here is search on the userid field using the  
> query params as  
> http://_ **.** _. **.** :9200/tournament/detail/\_search?q=userid:potter  
> and it returns the data
> 
> # {
> 
> - \_index: "tournament"
> - \_type: "detail"
> - \_id: "22|potter"
> - 
> - 
> 
> \_source: {  
> o tournamentid: 22  
> o userid: "potter"  
> o date: "2008-06-16T18:30:00.000Z"  
> o score: 276.62  
> o tries: 1  
> o gameid: 32  
> o gamename: "Caravan Toss"  
> o status: 3  
> o scoretype: 3  
> o result: 1  
> }
> 
> }
> 
> # 
> 
> # 
> 
> - 
> 
> {
> 
> - \_index: "tournament"
> - \_type: "detail"
> - \_id: "593|harry\_potter"
> - 
> - 
> 
> \_source: {  
> o tournamentid: 593  
> o userid: "harry\_potter"  
> o date: "2009-04-01T18:30:00.000Z"  
> o score: 212  
> o tries: 1  
> o gameid: 732  
> o gamename: "Trick Blast Billiards"  
> o status: 3  
> o scoretype: 1  
> o result: 0  
> }
> 
> }
> 
> # 
> 
> - 
> 
> {
> 
> - \_index: "tournament"
> - \_type: "detail"
> - \_id: "602|harry\_potter"
> - 
> - 
> 
> \_source: {  
> o tournamentid: 602  
> o userid: "harry\_potter"  
> o date: "2009-04-01T18:30:00.000Z"  
> o score: 190  
> o tries: 2  
> o gameid: 16  
> o gamename: "Ski Run"  
> o status: 3  
> o scoretype: 1  
> o result: 0  
> }  
> }  
> BTW this was when the schema was set to "index": "analyzed" for the  
> userid field.
> 
> But when i changed the index field to not\_analysed i only got the  
> results for potter. But when i queried for the field  
> harry\_potter(http://_ **.** _.\*.\*\*:9200/tournament/detail/\_search?  
> q=userid:harry\_potter) i am unable to get the data for it even though  
> its there and i can see the data when i use a wild card like  
> \*harry\_potter.
> 
> And since I've changed the omit\_norms and omit\_term\_freq\_and\_positions  
> to true but to no effect.
> 
> What changes do i need to make in my schema to see the desired results.

---

<div class="post-metadata">

**Author:** ![ajgamer](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@ajgamer](https://discuss.elastic.co/u/ajgamer)\
**Post date:** [July 20, 2010, 9:30am UTC](https://discuss.elastic.co/t/query-search-yielding-unexpected-results/3118/3 "2010-07-20T09:30:53Z")

</div>

Thank you very much for you're reply, that did the trick for me.

P.S. Keep up the good work, I'm already a fan.

On Mon, Jul 19, 2010 at 11:28 PM, Shay Banon  
[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> Before version 0.9 (which is master now), not\_analyzed fields were still  
> tokenized when used in a query string explicitly. You should define the  
> analyzer to be "keyword" (sounds strange, I know) even when its not  
> analyzed. This is done for by default in upcoming 0.9.
> 
> -shay.banon
> 
> On Mon, Jul 19, 2010 at 4:09 PM, ajgamer [abie.joseph14@gmail.com](mailto:abie.joseph14@gmail.com) wrote:
> 
> > Hi,
> > 
> > I am working with elasticsearch version 0.7 and have encountered my  
> > first roadblock. I have two mappings named detail and master. The  
> > schema for detail is as follows :  
> > {  
> > "properties": {
> > 
> > ```
> > \"userid\": {
> > \"type\": \"string\",
> > \"index_name\": \"userid\",
> > \"index\": \"not_analyzed\",
> > \"store\": \"no\",
> > \"term_vector\": \"no\",
> > \"boost\": 1.0,
> > \"omit_norms\": true,
> > \"omit_term_freq_and_positions\": true
> > },
> > }
> > 
> > ```
> > 
> > }
> > 
> > What i'm trying to do here is search on the userid field using the  
> > query params as  
> > http://_ **.** _. **.** :9200/tournament/detail/\_search?q=userid:potter  
> > and it returns the data
> > 
> > # {
> > 
> > - \_index: "tournament"
> > - \_type: "detail"
> > - \_id: "22|potter"
> > - 
> > - 
> > 
> > \_source: {  
> > o tournamentid: 22  
> > o userid: "potter"  
> > o date: "2008-06-16T18:30:00.000Z"  
> > o score: 276.62  
> > o tries: 1  
> > o gameid: 32  
> > o gamename: "Caravan Toss"  
> > o status: 3  
> > o scoretype: 3  
> > o result: 1  
> > }
> > 
> > }
> > 
> > # 
> > 
> > # 
> > 
> > - 
> > 
> > {
> > 
> > - \_index: "tournament"
> > - \_type: "detail"
> > - \_id: "593|harry\_potter"
> > - 
> > - 
> > 
> > \_source: {  
> > o tournamentid: 593  
> > o userid: "harry\_potter"  
> > o date: "2009-04-01T18:30:00.000Z"  
> > o score: 212  
> > o tries: 1  
> > o gameid: 732  
> > o gamename: "Trick Blast Billiards"  
> > o status: 3  
> > o scoretype: 1  
> > o result: 0  
> > }
> > 
> > }
> > 
> > # 
> > 
> > - 
> > 
> > {
> > 
> > - \_index: "tournament"
> > - \_type: "detail"
> > - \_id: "602|harry\_potter"
> > - 
> > - 
> > 
> > \_source: {  
> > o tournamentid: 602  
> > o userid: "harry\_potter"  
> > o date: "2009-04-01T18:30:00.000Z"  
> > o score: 190  
> > o tries: 2  
> > o gameid: 16  
> > o gamename: "Ski Run"  
> > o status: 3  
> > o scoretype: 1  
> > o result: 0  
> > }  
> > }  
> > BTW this was when the schema was set to "index": "analyzed" for the  
> > userid field.
> > 
> > But when i changed the index field to not\_analysed i only got the  
> > results for potter. But when i queried for the field  
> > harry\_potter(http://_ **.** _.\*.\*\*:9200/tournament/detail/\_search?  
> > q=userid:harry\_potter) i am unable to get the data for it even though  
> > its there and i can see the data when i use a wild card like  
> > \*harry\_potter.
> > 
> > And since I've changed the omit\_norms and omit\_term\_freq\_and\_positions  
> > to true but to no effect.
> > 
> > What changes do i need to make in my schema to see the desired results.

---

<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:22am UTC](https://discuss.elastic.co/t/query-search-yielding-unexpected-results/3118/4 "2017-07-06T04:22:04Z")

</div>


