# Hyphen search with wildcard '\*' and normal serach

**URL:** <https://discuss.elastic.co/t/hyphen-search-with-wildcard-and-normal-serach/9984>\
**Category:** Elasticsearch\
**Created:** [December 7, 2012, 9:03am UTC](https://discuss.elastic.co/t/hyphen-search-with-wildcard-and-normal-serach/9984 "2012-12-07T09:03:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![aps](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@aps](https://discuss.elastic.co/u/aps)\
**Post date:** [December 7, 2012, 9:03am UTC](https://discuss.elastic.co/t/hyphen-search-with-wildcard-and-normal-serach/9984/1 "2012-12-07T09:03:28Z")

</div>

Hi All,

We are stuck in a situation where we need to search exact hyphen query and  
others as wildcard query. We have 3 document type in our index  
customer,quotation, and devices respectively. We are allowing user to  
serach on minimum 4 characters hence we need to use wildcard.

The problem is quotation number contains hyphen "-" and we have to search  
the complete data for e.g. "QNMP-1900" should not be searched as QNMP and  
1900. That means if I search for "QNMP-19" then is should search for all  
records start with QNMP-19.

Rest search query should also works with wildcard. I have tried keyword  
analyzer, not\_analyzed and token but no luck. I tried query\_string and text  
query but the result is breaking string based on hyphen.

Any help would be highly appreciated.

Thanks.

--

---

<div class="post-metadata">

**Author:** ![pcdinh](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@pcdinh](https://discuss.elastic.co/u/pcdinh)\
**Post date:** [December 7, 2012, 9:07am UTC](https://discuss.elastic.co/t/hyphen-search-with-wildcard-and-normal-serach/9984/2 "2012-12-07T09:07:13Z")

</div>

Have you looked at word delimiter filter  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/word-delimiter-tokenfilter.html)?

On Fri, Dec 7, 2012 at 4:03 PM, aps [pushkardkumar@gmail.com](mailto:pushkardkumar@gmail.com) wrote:

> Hi All,
> 
> We are stuck in a situation where we need to search exact hyphen query and  
> others as wildcard query. We have 3 document type in our index  
> customer,quotation, and devices respectively. We are allowing user to  
> serach on minimum 4 characters hence we need to use wildcard.
> 
> The problem is quotation number contains hyphen "-" and we have to search  
> the complete data for e.g. "QNMP-1900" should not be searched as QNMP and  
> 1900. That means if I search for "QNMP-19" then is should search for all  
> records start with QNMP-19.
> 
> Rest search query should also works with wildcard. I have tried keyword  
> analyzer, not\_analyzed and token but no luck. I tried query\_string and text  
> query but the result is breaking string based on hyphen.
> 
> Any help would be highly appreciated.
> 
> Thanks.
> 
> --

--  
Spica Framework: [Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/spica)  
[http://www.twitter.com/pcdinh](http://www.twitter.com/pcdinh)  
[http://groups.google.com/group/phpvietnam](http://groups.google.com/group/phpvietnam)

--

---

<div class="post-metadata">

**Author:** ![aps](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@aps](https://discuss.elastic.co/u/aps)\
**Post date:** [December 7, 2012, 9:18am UTC](https://discuss.elastic.co/t/hyphen-search-with-wildcard-and-normal-serach/9984/3 "2012-12-07T09:18:05Z")

</div>

I tried it but couldn't find the proper settings to search hyphen.

On Friday, 7 December 2012 11:07:13 UTC+2, pcdinh wrote:

> Have you looked at word delimiter filter  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/word-delimiter-tokenfilter.html)?
> 
> On Fri, Dec 7, 2012 at 4:03 PM, aps \<[pushka...@gmail.com](mailto:pushka...@gmail.com) \<javascript:\>\>wrote:
> 
> > Hi All,
> > 
> > We are stuck in a situation where we need to search exact hyphen query  
> > and others as wildcard query. We have 3 document type in our index  
> > customer,quotation, and devices respectively. We are allowing user to  
> > serach on minimum 4 characters hence we need to use wildcard.
> > 
> > The problem is quotation number contains hyphen "-" and we have to search  
> > the complete data for e.g. "QNMP-1900" should not be searched as QNMP and  
> > 1900. That means if I search for "QNMP-19" then is should search for all  
> > records start with QNMP-19.
> > 
> > Rest search query should also works with wildcard. I have tried keyword  
> > analyzer, not\_analyzed and token but no luck. I tried query\_string and text  
> > query but the result is breaking string based on hyphen.
> > 
> > Any help would be highly appreciated.
> > 
> > Thanks.
> > 
> > --
> 
> --  
> Spica Framework: [Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/spica)  
> [http://www.twitter.com/pcdinh](http://www.twitter.com/pcdinh)  
> [http://groups.google.com/group/phpvietnam](http://groups.google.com/group/phpvietnam)

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 7, 2012, 4:20pm UTC](https://discuss.elastic.co/t/hyphen-search-with-wildcard-and-normal-serach/9984/4 "2012-12-07T16:20:57Z")

</div>

I cannot think of a reason why indexing this data as not analyzed and  
searching with wildcard wouldn't work for you. Could you change this  
gist [https://groups.google.com/d/topic/elasticsearch/3YXgoiZqQm4/discussion · GitHub](https://gist.github.com/4234377) to demonstrate your use case?

On Friday, December 7, 2012 4:18:05 AM UTC-5, aps wrote:

> I tried it but couldn't find the proper settings to search hyphen.
> 
> On Friday, 7 December 2012 11:07:13 UTC+2, pcdinh wrote:
> 
> > Have you looked at word delimiter filter  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/word-delimiter-tokenfilter.html)?
> > 
> > On Fri, Dec 7, 2012 at 4:03 PM, aps [pushka...@gmail.com](mailto:pushka...@gmail.com) wrote:
> > 
> > > Hi All,
> > > 
> > > We are stuck in a situation where we need to search exact hyphen query  
> > > and others as wildcard query. We have 3 document type in our index  
> > > customer,quotation, and devices respectively. We are allowing user to  
> > > serach on minimum 4 characters hence we need to use wildcard.
> > > 
> > > The problem is quotation number contains hyphen "-" and we have to  
> > > search the complete data for e.g. "QNMP-1900" should not be searched as  
> > > QNMP and 1900. That means if I search for "QNMP-19" then is should search  
> > > for all records start with QNMP-19.
> > > 
> > > Rest search query should also works with wildcard. I have tried keyword  
> > > analyzer, not\_analyzed and token but no luck. I tried query\_string and text  
> > > query but the result is breaking string based on hyphen.
> > > 
> > > Any help would be highly appreciated.
> > > 
> > > Thanks.
> > > 
> > > --
> > 
> > --  
> > Spica Framework: [Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/spica)  
> > [http://www.twitter.com/pcdinh](http://www.twitter.com/pcdinh)  
> > [http://groups.google.com/group/phpvietnam](http://groups.google.com/group/phpvietnam)

--

---

<div class="post-metadata">

**Author:** ![bnic](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@bnic](https://discuss.elastic.co/u/bnic)\
**Post date:** [December 8, 2012, 7:06pm UTC](https://discuss.elastic.co/t/hyphen-search-with-wildcard-and-normal-serach/9984/5 "2012-12-08T19:06:18Z")

</div>

If I understand the problem your searches for XXX-999 are being tokenized into two separate tokens? The standard tokenizer will do that, I believe I use the whitespace tokenizer to avoid that issue.

---

<div class="post-metadata">

**Author:** ![aps](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@aps](https://discuss.elastic.co/u/aps)\
**Post date:** [December 10, 2012, 7:54am UTC](https://discuss.elastic.co/t/hyphen-search-with-wildcard-and-normal-serach/9984/6 "2012-12-10T07:54:15Z")

</div>

I am using global search where not\_analyzed required term query. As I  
specified I have 3 document type and I am searching on all.  
Please check the query which I am using directly on index.

{

"from": "0",

"size": "10",

"query": {

```
"query_string": {

  "default_field": "_all",

  "default_operator": "AND",

  "analyze_wildcard": true,

  "query": "QNAM-45*"

}

```

}

}

Now in this query, search result are giving me result starts with QNAM and  
45 both. The document type is set to default.

On Friday, 7 December 2012 18:20:57 UTC+2, Igor Motov wrote:

> I cannot think of a reason why indexing this data as not analyzed and  
> searching with wildcard wouldn't work for you. Could you change this gist  
> [https://groups.google.com/d/topic/elasticsearch/3YXgoiZqQm4/discussion · GitHub](https://gist.github.com/4234377) to demonstrate your use case?
> 
> On Friday, December 7, 2012 4:18:05 AM UTC-5, aps wrote:
> 
> > I tried it but couldn't find the proper settings to search hyphen.
> > 
> > On Friday, 7 December 2012 11:07:13 UTC+2, pcdinh wrote:
> > 
> > > Have you looked at word delimiter filter  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/word-delimiter-tokenfilter.html)?
> > > 
> > > On Fri, Dec 7, 2012 at 4:03 PM, aps [pushka...@gmail.com](mailto:pushka...@gmail.com) wrote:
> > > 
> > > > Hi All,
> > > > 
> > > > We are stuck in a situation where we need to search exact hyphen query  
> > > > and others as wildcard query. We have 3 document type in our index  
> > > > customer,quotation, and devices respectively. We are allowing user to  
> > > > serach on minimum 4 characters hence we need to use wildcard.
> > > > 
> > > > The problem is quotation number contains hyphen "-" and we have to  
> > > > search the complete data for e.g. "QNMP-1900" should not be searched as  
> > > > QNMP and 1900. That means if I search for "QNMP-19" then is should search  
> > > > for all records start with QNMP-19.
> > > > 
> > > > Rest search query should also works with wildcard. I have tried keyword  
> > > > analyzer, not\_analyzed and token but no luck. I tried query\_string and text  
> > > > query but the result is breaking string based on hyphen.
> > > > 
> > > > Any help would be highly appreciated.
> > > > 
> > > > Thanks.
> > > > 
> > > > --
> > > 
> > > --  
> > > Spica Framework: [Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/spica)  
> > > [http://www.twitter.com/pcdinh](http://www.twitter.com/pcdinh)  
> > > [http://groups.google.com/group/phpvietnam](http://groups.google.com/group/phpvietnam)

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 10, 2012, 3:46pm UTC](https://discuss.elastic.co/t/hyphen-search-with-wildcard-and-normal-serach/9984/7 "2012-12-10T15:46:46Z")

</div>

This query is searching the \_all field which by default combines all fields  
in your documents into a single field which is analyzed by the default  
analyzer. You need to search individual fields (not \_all) for the field  
specific analyzer to be applied.

On Monday, December 10, 2012 2:54:15 AM UTC-5, aps wrote:

> I am using global search where not\_analyzed required term query. As I  
> specified I have 3 document type and I am searching on all.  
> Please check the query which I am using directly on index.
> 
> {
> 
> "from": "0",
> 
> "size": "10",
> 
> "query": {
> 
> ```
> "query_string": {
> 
> "default_field": "_all",
> 
> "default_operator": "AND",
> 
> "analyze_wildcard": true,
> 
> "query": "QNAM-45*"
> 
> }
> 
> ```
> 
> }
> 
> }
> 
> Now in this query, search result are giving me result starts with QNAM and  
> 45 both. The document type is set to default.
> 
> On Friday, 7 December 2012 18:20:57 UTC+2, Igor Motov wrote:
> 
> > I cannot think of a reason why indexing this data as not analyzed and  
> > searching with wildcard wouldn't work for you. Could you change this gist  
> > [https://groups.google.com/d/topic/elasticsearch/3YXgoiZqQm4/discussion · GitHub](https://gist.github.com/4234377) to demonstrate your use case?
> > 
> > On Friday, December 7, 2012 4:18:05 AM UTC-5, aps wrote:
> > 
> > > I tried it but couldn't find the proper settings to search hyphen.
> > > 
> > > On Friday, 7 December 2012 11:07:13 UTC+2, pcdinh wrote:
> > > 
> > > > Have you looked at word delimiter filter  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/word-delimiter-tokenfilter.html)?
> > > > 
> > > > On Fri, Dec 7, 2012 at 4:03 PM, aps [pushka...@gmail.com](mailto:pushka...@gmail.com) wrote:
> > > > 
> > > > > Hi All,
> > > > > 
> > > > > We are stuck in a situation where we need to search exact hyphen query  
> > > > > and others as wildcard query. We have 3 document type in our index  
> > > > > customer,quotation, and devices respectively. We are allowing user to  
> > > > > serach on minimum 4 characters hence we need to use wildcard.
> > > > > 
> > > > > The problem is quotation number contains hyphen "-" and we have to  
> > > > > search the complete data for e.g. "QNMP-1900" should not be searched as  
> > > > > QNMP and 1900. That means if I search for "QNMP-19" then is should search  
> > > > > for all records start with QNMP-19.
> > > > > 
> > > > > Rest search query should also works with wildcard. I have tried  
> > > > > keyword analyzer, not\_analyzed and token but no luck. I tried query\_string  
> > > > > and text query but the result is breaking string based on hyphen.
> > > > > 
> > > > > Any help would be highly appreciated.
> > > > > 
> > > > > Thanks.
> > > > > 
> > > > > --
> > > > 
> > > > --  
> > > > Spica Framework: [Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/spica)  
> > > > [http://www.twitter.com/pcdinh](http://www.twitter.com/pcdinh)  
> > > > [http://groups.google.com/group/phpvietnam](http://groups.google.com/group/phpvietnam)

--

---

<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, 3:00am UTC](https://discuss.elastic.co/t/hyphen-search-with-wildcard-and-normal-serach/9984/8 "2017-07-06T03:00:32Z")

</div>


