# Allow user to search "-". like QNAM-109

**URL:** <https://discuss.elastic.co/t/allow-user-to-search-like-qnam-109/12942>\
**Category:** Elasticsearch\
**Created:** [July 25, 2013, 4:35pm UTC](https://discuss.elastic.co/t/allow-user-to-search-like-qnam-109/12942 "2013-07-25T16:35:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hdvyas007](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hdvyas007](https://discuss.elastic.co/u/hdvyas007)\
**Post date:** [July 25, 2013, 4:35pm UTC](https://discuss.elastic.co/t/allow-user-to-search-like-qnam-109/12942/1 "2013-07-25T16:35:36Z")

</div>

Hi All,

In our project, system allows user to search text which may contain "-".  
For example user enter QNAM-109 as search text and ES should retrieve all  
docs which contains QNAM-109 as value of any of field of those docs.  
further more ES should return all documents whose fields' value start with  
QNAM-109.

For above requirement I created index in following way.

{  
"settings": {  
"index": {  
"number\_of\_shards": 8,  
"number\_of\_replicas": 0,  
"analysis": {  
"analyzer": {  
"uax\_url\_email": {  
"filter": [  
"standard",  
"lowercase",  
"stop"  
],  
"tokenizer": "uax\_url\_email"  
},  
"whitespace": {  
"tokenizer": "whitespace",  
"filter": [  
"standard",  
"lowercase",  
"stop"  
]  
}  
}  
}  
}  
},  
"mappings": {  
"quotation": {  
"\_source": {  
"enabled": true  
},  
"properties": {  
"QuotationNo": {  
"type": "string",  
"analyzer": "whitespace"  
},  
"Status": {  
"type": "string"  
},  
"CreateDate": {  
"type": "string",  
"index": "no"  
},  
"ExpiryDate": {  
"type": "string",  
"index": "no"  
},  
"FirstName": {  
"type": "string",  
"index": "no"  
},  
"LastName": {  
"type": "string"  
},  
"EmailIds": {  
"type": "string",  
"analyzer": "uax\_url\_email"  
},  
"CellNumbers": {  
"type": "string"  
}  
}  
}  
}  
}

* * *

Here my sample data that I inserted in ES

{  
"Status" :"Active",  
"QuotationNo": "qnam-1099",  
"EmailIds" : ["vyas@s.com"],  
"FirstName": "yasop",  
"LastName": "qexhd",  
"CellNumbers" : ["852456"]  
}

{  
"Status" :"Active",  
"QuotationNo": "qnam-1095",  
"EmailIds" : ["qhul@aber.com"],  
"FirstName": "qhul",  
"LastName": "uiox",  
"CellNumbers" : ["581236"]  
}

{  
"Status" :"Active",  
"QuotationNo": "qnam-1081",  
"EmailIds" : ["poxr@poxr.com"],  
"FirstName": "poxr",  
"LastName": "poxr",  
"CellNumbers" : ["895255"]  
}

Now I fire following search query. I am expecting all documents whose  
fields' value start with qnam-109.

{  
"from": "0",  
"size": "10",  
"query": {  
"query\_string": {  
"default\_field": "\_all",  
"default\_operator": "AND",  
"analyze\_wildcard": true,  
"query": "qnam-109\*"  
}  
}  
}

Above query should returns only two documents out of three documents that I  
inserted in ES. As one document contains qnam-1081. But unfortunately  
previous query returns all documents. It also fetch document with qnam-1081  
in "QuotationNo".  
Can anyone please suggest what I am doing wrong? Or can anyone suggest ES  
queries to create index and search from index which may contain "-" in any  
one field of a type within that index.

Note:- Our search UI contains only one search text box like Google. User  
enter anything to search from index. and search query should find all types  
of Index that satisfies search text. That is the reason I have created  
search query like above.  
second thing some of field of document may contain email address. and we  
also giving facility to user to find document from email address. that is  
why I used uax\_url\_email as analyzer also.

Thanks and Regards

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [July 26, 2013, 6:14am UTC](https://discuss.elastic.co/t/allow-user-to-search-like-qnam-109/12942/2 "2013-07-26T06:14:32Z")

</div>

Hey,

you might want to take a closer look at the match and the prefix queries  
and play around with those.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--Alex

On Thu, Jul 25, 2013 at 6:35 PM, hdvyas [hdvyas007@gmail.com](mailto:hdvyas007@gmail.com) wrote:

> Hi All,
> 
> In our project, system allows user to search text which may contain "-".  
> For example user enter QNAM-109 as search text and ES should retrieve all  
> docs which contains QNAM-109 as value of any of field of those docs.  
> further more ES should return all documents whose fields' value start with  
> QNAM-109.
> 
> For above requirement I created index in following way.
> 
> {  
> "settings": {  
> "index": {  
> "number\_of\_shards": 8,  
> "number\_of\_replicas": 0,  
> "analysis": {  
> "analyzer": {  
> "uax\_url\_email": {  
> "filter": [  
> "standard",  
> "lowercase",  
> "stop"  
> ],  
> "tokenizer": "uax\_url\_email"  
> },  
> "whitespace": {  
> "tokenizer": "whitespace",  
> "filter": [  
> "standard",  
> "lowercase",  
> "stop"  
> ]  
> }  
> }  
> }  
> }  
> },  
> "mappings": {  
> "quotation": {  
> "\_source": {  
> "enabled": true  
> },  
> "properties": {  
> "QuotationNo": {  
> "type": "string",  
> "analyzer": "whitespace"  
> },  
> "Status": {  
> "type": "string"  
> },  
> "CreateDate": {  
> "type": "string",  
> "index": "no"  
> },  
> "ExpiryDate": {  
> "type": "string",  
> "index": "no"  
> },  
> "FirstName": {  
> "type": "string",  
> "index": "no"  
> },  
> "LastName": {  
> "type": "string"  
> },  
> "EmailIds": {  
> "type": "string",  
> "analyzer": "uax\_url\_email"  
> },  
> "CellNumbers": {  
> "type": "string"  
> }  
> }  
> }  
> }  
> }
> 
> * * *
> 
> Here my sample data that I inserted in ES
> 
> {  
> "Status" :"Active",  
> "QuotationNo": "qnam-1099",  
> "EmailIds" : ["[vyas@s.com](mailto:vyas@s.com)"],  
> "FirstName": "yasop",  
> "LastName": "qexhd",  
> "CellNumbers" : ["852456"]  
> }
> 
> {  
> "Status" :"Active",  
> "QuotationNo": "qnam-1095",  
> "EmailIds" : ["[qhul@aber.com](mailto:qhul@aber.com)"],  
> "FirstName": "qhul",  
> "LastName": "uiox",  
> "CellNumbers" : ["581236"]  
> }
> 
> {  
> "Status" :"Active",  
> "QuotationNo": "qnam-1081",  
> "EmailIds" : ["[poxr@poxr.com](mailto:poxr@poxr.com)"],  
> "FirstName": "poxr",  
> "LastName": "poxr",  
> "CellNumbers" : ["895255"]  
> }
> 
> Now I fire following search query. I am expecting all documents whose  
> fields' value start with qnam-109.
> 
> {  
> "from": "0",  
> "size": "10",  
> "query": {  
> "query\_string": {  
> "default\_field": "\_all",  
> "default\_operator": "AND",  
> "analyze\_wildcard": true,  
> "query": "qnam-109\*"  
> }  
> }  
> }
> 
> Above query should returns only two documents out of three documents that  
> I inserted in ES. As one document contains qnam-1081. But unfortunately  
> previous query returns all documents. It also fetch document with qnam-1081  
> in "QuotationNo".  
> Can anyone please suggest what I am doing wrong? Or can anyone suggest ES  
> queries to create index and search from index which may contain "-" in any  
> one field of a type within that index.
> 
> Note:- Our search UI contains only one search text box like Google. User  
> enter anything to search from index. and search query should find all types  
> of Index that satisfies search text. That is the reason I have created  
> search query like above.  
> second thing some of field of document may contain email address. and we  
> also giving facility to user to find document from email address. that is  
> why I used uax\_url\_email as analyzer also.
> 
> Thanks and Regards
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:24am UTC](https://discuss.elastic.co/t/allow-user-to-search-like-qnam-109/12942/3 "2017-07-06T02:24:26Z")

</div>


