# Elastic Serach query not matching encoded string(45" - 45&quot;)

**URL:** <https://discuss.elastic.co/t/elastic-serach-query-not-matching-encoded-string-45-45-quot/171941>\
**Category:** Elasticsearch\
**Created:** [March 12, 2019, 12:03pm UTC](https://discuss.elastic.co/t/elastic-serach-query-not-matching-encoded-string-45-45-quot/171941 "2019-03-12T12:03:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![prashu039](https://avatars.discourse-cdn.com/v4/letter/p/c37758/32.png) [@prashu039](https://discuss.elastic.co/u/prashu039)\
**Post date:** [March 12, 2019, 12:03pm UTC](https://discuss.elastic.co/t/elastic-serach-query-not-matching-encoded-string-45-45-quot/171941/1 "2019-03-12T12:03:21Z")

</div>

We have product details which contain length parameter which has value as 45"(45 inch) So on indexing this product details I am converting 45" to encoded string ie 45&quot ;  
So on search i will send the search parameter encoded ie if user search product on 45" i will send it as 45&quot. But elastic search doesn't give any result.  
This filed in product details is mapped as -  
product\_length is array  
"properties": {  
"product\_length": {  
"type": "text",  
"fields": {  
"raw": {  
"type": "keyword"  
}  
},  
"fielddata": true  
}  
}  
and to find products which have product length 45" i am using bellow query:

Search term is encoded before search ie 45" to 45&quot ;

{  
"query": {  
"bool": {  
"must": [{  
"terms": {  
"product\_length": ["45&quot ;"]  
}  
}]  
}  
}  
}

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

But it return's: "hits":

Is there another way I should follow?

---

<div class="post-metadata">

**Author:** ![prashu039](https://avatars.discourse-cdn.com/v4/letter/p/c37758/32.png) [@prashu039](https://discuss.elastic.co/u/prashu039)\
**Post date:** [March 12, 2019, 5:17pm UTC](https://discuss.elastic.co/t/elastic-serach-query-not-matching-encoded-string-45-45-quot/171941/2 "2019-03-12T17:17:56Z")

</div>

I tried with wildcard query but it's not working  
{  
"wildcard": {  
"product\_description": {  
"value": "45&quot ;",  
"boost": 1.5  
}  
}  
}  
Then i tried with "simple\_query\_string" , its Working on exact match but i couldn't able to get result for partial search term ie 45  
{  
"simple\_query\_string" : {  
"fields" : ["product\_name","tags"],  
"query" : "45&quot ;"  
}  
}  
then i tried with "match" query it solves the problem:  
{  
"match": {  
"tags": "45&quot ;\*"  
}  
}

---

<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:** [April 9, 2019, 5:17pm UTC](https://discuss.elastic.co/t/elastic-serach-query-not-matching-encoded-string-45-45-quot/171941/3 "2019-04-09T17:17:59Z")

</div>

Closed on April 9, 2019, 5:17pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
