# Match query is working differently for few inputs

**URL:** https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426
**Category:** Elasticsearch
**Created:** [July 13, 2015, 9:42am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426 "2015-07-13T09:42:51Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)
#### Post date: [July 13, 2015, 9:42am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/1 "2015-07-13T09:42:51Z")

</div>

Hi,  
I kept following mappings:

PUT pdlfull/pdlfull\_type/\_mapping  
{  
"pdlfull\_type": {  
"properties": {  
"GenericDescriptionId": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"GroupNumber": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"catalogDescriptions": {  
"properties": {  
"catalogDescriptionId": {  
"type": "long"  
}  
}  
},  
"description": {  
"type": "string",  
"analyzer": "analyzer\_startswith",  
"fields": {  
"sort\_field": {  
"type": "string",  
"analyzer": "keyword\_analyzer"  
}  
}  
}  
}

And the relevant analyzers I have used in mappings as shown below :

"analysis": {  
"analyzer": {  
"keyword\_analyzer": {  
"filter": "lowercase",  
"tokenizer": "keyword"  
},  
"analyzer\_startswith": {  
"filter": [  
"lowercase"  
],  
"tokenizer": "whitespace"  
},  
"whitespace\_analyzer": {  
"type": "custom",  
"filter": [  
"lowercase",  
"asciifolding"  
],  
"tokenizer": "whitespace"  
},  
"wordAnalyzer": {  
"type": "custom",  
"filter": [  
"lowercase",  
"asciifolding",  
"nGram\_filter"  
],  
"tokenizer": "whitespace"  
}  
},  
"filter": {  
"nGram\_filter": {  
"max\_gram": "20",  
"min\_gram": "1",  
"type": "nGram",  
"token\_chars": [  
"letter",  
"digit",  
"punctuation",  
"symbol"  
]  
}  
}

These are the settings I have used,  
My sample description field data is(where am searching only in description field) :

"A Frame & Trunnion Kat"  
"A/C Bypass pulley"  
"A/C Bypass pulley(Belts)"  
"A/T Fluid Capacity"  
"A/T overdrive Button kit"  
"A/T shift bezel"  
"Abc accumulator"  
"ABS Anti-skid Relay"  
"ABS Anti-skid switch"

My Query is:

GET pdlfull/pdlfull\_type/\_search  
{  
"query": {  
"match\_phrase\_prefix": {  
"description":"a/c b"

```
    }
},

```

"sort":  
{  
"description.sort\_field"  
{  
"order":"asc"  
}  
}  
}

The above query is not returning any records.

When am giving the query "a/t s","abc a","a/t f","a/t o","A F" am getting records..

May I know the reason, even am not getting records with few prefixes am unable to find out where the problem is and why my query is behaving differently to different inputs..

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [July 13, 2015, 9:57am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/2 "2015-07-13T09:57:17Z")

</div>

You may find it useful to use the [Explain API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html) on both the queries that work and the ones that don't to see what the difference is and determine what's causing this behaviour.

It may also be useful to use the [Analyze API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-analyze.html) to test that each of the examples in the description field data you listed are creating the terms you expect.

---

<div class="post-metadata">

### Author: ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)
#### Post date: [July 13, 2015, 10:15am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/3 "2015-07-13T10:15:31Z")

</div>

The following query I have used with Explain:

GET pdlfull/pdlfull\_type/AU6F0k0L3NytkeZBUPfI/\_explain  
{  
"query": {  
"match": {  
"description":  
{  
"query": "abs a",  
"operator": "and",  
"type": "phrase\_prefix",  
"prefix\_length": 1  
}

```
    }
}

```

}

This is giving result as:

{  
"\_index": "pdlfull",  
"\_type": "pdlfull\_type",  
"\_id": "AU6F0k0L3NytkeZBUPfI",  
"matched": false,  
"explanation": {  
"value": 0,  
"description": "no matching term"  
}  
}

When I have used the query:

GET pdlfull/pdlfull\_type/AU6F0l6b3NytkeZBURzM/\_explain  
{  
"query": {  
"match": {  
"description":  
{  
"query": "a/t f",  
"operator": "and",  
"type": "phrase\_prefix",  
"prefix\_length": 1  
}

```
    }
}

```

}

Got result as:

"\_index": "pdlfull",  
"\_type": "pdlfull\_type",  
"\_id": "AU6F0l6b3NytkeZBURzM",  
"matched": true,  
"explanation": {  
"value": 203.01616,  
"description": "weight(description:"a/t (filler fro forward front fa flow flange flasher fuel flywheel/parts frame frequency fan four flange, fluid f fork/parts flares fuel/water flex final fusible float fog fender follower fuse fit facing filter flasher, flare flng(emissions) fitting, full flywheel freeze fork floor fitting frnt fast formed feedback filter, foot fn fairing front/rear)" in 449) [PerFieldSimilarity], result of:",  
"details": [  
{  
"value": 203.01616,  
"description": "fieldWeight in 449, product of:",  
"details": [  
{  
"value": 1,  
"description": "tf(freq=1.0), with freq of:",  
"details": [  
{  
"value": 1,  
"description": "phraseFreq=1.0"  
}  
]  
},  
{  
"value": 406.03232,  
"description": "idf(), sum of:",  
"details": [  
{  
"value": 8.127894,  
"description": "idf(docFreq=3, maxDocs=4985)"  
},  
{  
"value": 7.029282,  
"description": "idf(docFreq=11, maxDocs=4985)"  
},  
{  
.  
.  
.  
.  
}

Something like this,  
may I know, why I got the explanation as 'false' match for 'abs a' even though records are there with that prefix and 'true' match for 'a/t f' as am using the same prefix query for both???

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [July 13, 2015, 10:21am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/4 "2015-07-13T10:21:05Z")

</div>

Could you try running the following?

```auto
curl -XGET 'localhost:9200/pdlfull/_analyze?analyzer=analyzer_startswith' -d 'ABS Anti-skid Relay'

```

and

```auto
curl -XGET 'localhost:9200/pdlfull/_analyze?analyzer=analyzer_startswith' -d 'A/T Fluid Capacity'

```

This will help to see the tokens the analyzer is producing in the index for that field

---

<div class="post-metadata">

### Author: ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)
#### Post date: [July 13, 2015, 10:21am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/5 "2015-07-13T10:21:52Z")

</div>

May I know how to check analyser output:  
I have used query as:

GET pdlfull/\_analyze?analyzer=analyzer\_startswith a/c b

it is showing:

{  
"error": "ElasticsearchIllegalArgumentException[text is missing]",  
"status": 400  
}

So how can I write the GET statement not in curl

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [July 13, 2015, 10:27am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/6 "2015-07-13T10:27:05Z")

</div>

What are you using to send requests to Elasticsearch?

You need to put 'a/c b' in the body of the request. This will be different depending on what tool you are using to send requests. I would look at the documentation for the tool.

---

<div class="post-metadata">

### Author: ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)
#### Post date: [July 13, 2015, 10:29am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/7 "2015-07-13T10:29:06Z")

</div>

> [@colings86](#):
>
> curl -XGET 'localhost:9200/pdlfull/\_analyze?analyzer=analyzer\_startswith' -d 'ABS Anti-skid Relay'

Am using sense plugin for that

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [July 13, 2015, 10:35am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/8 "2015-07-13T10:35:21Z")

</div>

Try the following instead:

```auto
GET /pdlfull/_analyze?analyzer=analyzer_startswith&text=ABS Anti-skid Relay

```

and

```auto
GET /pdlfull/_analyze?analyzer=analyzer_startswith&text=A/T Fluid Capacity

```

and

```auto
GET /pdlfull/_analyze?analyzer=analyzer_startswith&text=abs a

```

and

```auto
GET /pdlfull/_analyze?analyzer=analyzer_startswith&text=a/t f

```

---

<div class="post-metadata">

### Author: ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)
#### Post date: [July 13, 2015, 10:40am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/9 "2015-07-13T10:40:14Z")

</div>

GET /pdlfull/\_analyze?analyzer=analyzer\_startswith&text=ABS Anti-skid Relay

Result:  
{  
"token": "abs",  
"start\_offset": 0,  
"end\_offset": 3,  
"type": "word",  
"position": 1  
},  
{  
"token": "anti-skid",  
"start\_offset": 4,  
"end\_offset": 13,  
"type": "word",  
"position": 2  
},  
{  
"token": "relay",  
"start\_offset": 14,  
"end\_offset": 19,  
"type": "word",  
"position": 3  
}

For the below text:  
GET /pdlfull/\_analyze?analyzer=analyzer\_startswith&text=abs a

Result:  
{  
"token": "abs",  
"start\_offset": 0,  
"end\_offset": 3,  
"type": "word",  
"position": 1  
},  
{  
"token": "a",  
"start\_offset": 4,  
"end\_offset": 5,  
"type": "word",  
"position": 2  
}

In the same way am getting the tokens for the other two text inputs...

---

<div class="post-metadata">

### Author: ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)
#### Post date: [July 13, 2015, 10:41am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/10 "2015-07-13T10:41:52Z")

</div>

Here am getting tokens for all the four inputs.. So where can I find the difference?

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [July 13, 2015, 10:48am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/11 "2015-07-13T10:48:11Z")

</div>

This is a bit strange, I was expecting there to be some differences in those outputs that would show the problem.

What version of Elasticsearch are you running?

---

<div class="post-metadata">

### Author: ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)
#### Post date: [July 13, 2015, 10:57am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/12 "2015-07-13T10:57:31Z")

</div>

Its 1.5.2..

---

<div class="post-metadata">

### Author: ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)
#### Post date: [July 13, 2015, 11:02am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/13 "2015-07-13T11:02:27Z")

</div>

Is it because of the mappings that I kept for the field 'description', I am using that analyser and the multi field type newly, so i don't know whether it may be a cause or not for this issue?

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [July 13, 2015, 11:11am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/14 "2015-07-13T11:11:10Z")

</div>

I have tried to reproduce your issue using the sense script in [this gist](https://gist.github.com/colings86/b310c32be9027e78e45c). Maybe you could try this on your environment to see if you can reproduce it on your cluster? If not, maybe you can try to modify the script so that it reproduces?

---

<div class="post-metadata">

### Author: ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)
#### Post date: [July 13, 2015, 11:17am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/15 "2015-07-13T11:17:44Z")

</div>

Hi Colin,  
Sorry, I didn't get your words...

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [July 13, 2015, 11:21am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/16 "2015-07-13T11:21:57Z")

</div>

I tried to re-create the problem you are seeing on my own cluster but I was not able to. On my cluster the queries return correctly. The requests I sent to my cluster to try to recreate the issue are listed at [the link I posted](https://gist.github.com/colings86/b310c32be9027e78e45c).

It would be a good idea for you to try to run the same steps that I did, by pasting the sense commands from that link into your sense client and running the commands (this will create a new index called `testIdx`). Can you let me know if you find the same issue with this new index?

---

<div class="post-metadata">

### Author: ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)
#### Post date: [July 13, 2015, 11:26am UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/17 "2015-07-13T11:26:57Z")

</div>

Hi Colin,  
The queries are returning the correct data with the new index in my cluster too.. Then why they are not returning for the old index?

---

<div class="post-metadata">

### Author: ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)
#### Post date: [July 13, 2015, 12:13pm UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/18 "2015-07-13T12:13:27Z")

</div>

Hi Colin,  
I have again created the index with same settings and mappings, and loaded the data. Now am able to get the data to any type of text input.  
Before I updated the keyword analyzer and the mappings with the multi-field type, as the mappings got updated without any conflicts there is no need to re-index the data hope so. But without re-indexing the data I faced the problem with few text inputs not giving any results.  
So do I need to re-index the data always, even though the settings and mappings got updated?

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [July 13, 2015, 12:16pm UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/19 "2015-07-13T12:16:39Z")

</div>

Yes you will need to re-index all your data if you change the mappings or settings. You are able to add new nulti-fields to an index without a conflict in the mappings but this will only add the new multi-fields for new index requests and will not add them for documents which are already indexed. The best approach is just to re-index any time you change your mappings.

---

<div class="post-metadata">

### Author: ![anusha6](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@anusha6](https://discuss.elastic.co/u/anusha6)
#### Post date: [July 13, 2015, 12:20pm UTC](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426/20 "2015-07-13T12:20:23Z")

</div>

Okay Colin. Thank you very much, this discussion gave me a good experience. 😃

[Next page](https://discuss.elastic.co/t/match-query-is-working-differently-for-few-inputs/25426.md?page=2)
