# Elasticsearch search fo words having '#' character

**URL:** <https://discuss.elastic.co/t/elasticsearch-search-fo-words-having-character/12737>\
**Category:** Elasticsearch\
**Created:** [July 10, 2013, 6:27am UTC](https://discuss.elastic.co/t/elasticsearch-search-fo-words-having-character/12737 "2013-07-10T06:27:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![prince](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@prince](https://discuss.elastic.co/u/prince)\
**Post date:** [July 10, 2013, 6:27am UTC](https://discuss.elastic.co/t/elasticsearch-search-fo-words-having-character/12737/1 "2013-07-10T06:27:35Z")

</div>

For example, I am right now searching like this:

[http://localhost:9200/posts/post/\_search?q=content:%23sachin](http://localhost:9200/posts/post/_search?q=content:%23sachin)

But, I am getting all the results with 'sachin' and not '#sachin'. Also, I am writing a regular expression for getting the count of terms. The facet looks like this:

"facets": {  
"content": {  
"terms": {  
"field": "content",  
"size": 1000,  
"all\_terms": false,  
"regex": "#sachin",  
"regex\_flags": [  
"DOTALL",  
"CASE\_INSENSITIVE"  
]  
}  
}  
}

This is not returning any values. I think it has something to do with escaping the '#' inside the regular expression, but I am not sure how to do it. I have tried to escape it \ and \, but it did not work. Can anyone help me in this regard?

---

<div class="post-metadata">

**Author:** ![prince](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@prince](https://discuss.elastic.co/u/prince)\
**Post date:** [July 10, 2013, 6:29am UTC](https://discuss.elastic.co/t/elasticsearch-search-fo-words-having-character/12737/2 "2013-07-10T06:29:58Z")

</div>

I have posted the same question on Stack Overflow ([http://stackoverflow.com/questions/17526736/elasticsearch-search-fo-words-having-character](http://stackoverflow.com/questions/17526736/elasticsearch-search-fo-words-having-character))

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [July 10, 2013, 8:46am UTC](https://discuss.elastic.co/t/elasticsearch-search-fo-words-having-character/12737/3 "2013-07-10T08:46:20Z")

</div>

Hello,

I think the standard  
analyzer[http://www.elasticsearch.org/guide/reference/index-modules/analysis/standard-analyzer/](http://www.elasticsearch.org/guide/reference/index-modules/analysis/standard-analyzer/)will  
get rid of your #, and that's why it doesn't show up in searches.

If you want exact matches for that field, the easiest way is to use index  
it as "not\_analyzed". Here's a curl example that should work;

> <https://gist.github.com/radu-gheorghe/5964537>

On Wed, Jul 10, 2013 at 9:29 AM, prince [prince@qburst.com](mailto:prince@qburst.com) wrote:

> I have posted the same question on Stack Overflow  
> (  
> [Elasticsearch search fo words having '#' character - Stack Overflow](http://stackoverflow.com/questions/17526736/elasticsearch-search-fo-words-having-character)  
> )
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Elasticsearch-search-fo-words-having-character-tp4037822p4037823.html](http://elasticsearch-users.115913.n3.nabble.com/Elasticsearch-search-fo-words-having-character-tp4037822p4037823.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> 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).

--  
[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

--  
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 10, 2013, 9:39am UTC](https://discuss.elastic.co/t/elasticsearch-search-fo-words-having-character/12737/4 "2013-07-10T09:39:55Z")

</div>

Hey,

you should not facet on analyzed fields, if you dont want to run out of  
memory pretty quickly (because every term of the inverted index gets loaded  
into memory for this field, which may be a lot, depending on the size of  
the index).

--Alex

On Wed, Jul 10, 2013 at 10:46 AM, Radu Gheorghe  
[radu.gheorghe@sematext.com](mailto:radu.gheorghe@sematext.com)wrote:

> Hello,
> 
> I think the standard analyzer[http://www.elasticsearch.org/guide/reference/index-modules/analysis/standard-analyzer/](http://www.elasticsearch.org/guide/reference/index-modules/analysis/standard-analyzer/)will get rid of your #, and that's why it doesn't show up in searches.
> 
> If you want exact matches for that field, the easiest way is to use index  
> it as "not\_analyzed". Here's a curl example that should work;  
> [index and search for a value containing # · GitHub](https://gist.github.com/radu-gheorghe/5964537)
> 
> On Wed, Jul 10, 2013 at 9:29 AM, prince [prince@qburst.com](mailto:prince@qburst.com) wrote:
> 
> > I have posted the same question on Stack Overflow  
> > (  
> > [Elasticsearch search fo words having '#' character - Stack Overflow](http://stackoverflow.com/questions/17526736/elasticsearch-search-fo-words-having-character)  
> > )
> > 
> > --  
> > View this message in context:  
> > [http://elasticsearch-users.115913.n3.nabble.com/Elasticsearch-search-fo-words-having-character-tp4037822p4037823.html](http://elasticsearch-users.115913.n3.nabble.com/Elasticsearch-search-fo-words-having-character-tp4037822p4037823.html)  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> > 
> > --  
> > 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).
> 
> --  
> [http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene
> 
> --  
> 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:** ![prince](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@prince](https://discuss.elastic.co/u/prince)\
**Post date:** [July 10, 2013, 11:02am UTC](https://discuss.elastic.co/t/elasticsearch-search-fo-words-having-character/12737/5 "2013-07-10T11:02:19Z")

</div>

Hi Radu,

But what I need is to search is really "analyzed", because if content is something like '#sachin big news, retires from ODI', it should get that on searching, but if it is like 'sachin, you are awesome', it should not get that on searching.

"not\_analyzed" will get only exact matches and is not useful for my usecase (Here, it will get only content with "#sachin" as the full text and not containing "#sachin")

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [July 10, 2013, 11:52am UTC](https://discuss.elastic.co/t/elasticsearch-search-fo-words-having-character/12737/6 "2013-07-10T11:52:13Z")

</div>

Hello,

In that case, you need to change your  
analyzer[http://www.elasticsearch.org/guide/reference/index-modules/analysis/](http://www.elasticsearch.org/guide/reference/index-modules/analysis/).  
Maybe Whitespace  
Analyzer[http://www.elasticsearch.org/guide/reference/index-modules/analysis/whitespace-analyzer/](http://www.elasticsearch.org/guide/reference/index-modules/analysis/whitespace-analyzer/)is  
more appropriate here?

Also, please note Alex's warning regarding memory usage. I'm not sure how  
your hardware and data look like, but might be worth paying some price at  
index time for more performance and less memory usage during searches. For  
example, you can parse your text for hashtags and store them in some "tags"  
field (which can be an array), that you can store as not\_analyzed and facet  
separately.

Best regards,  
Radu

On Wed, Jul 10, 2013 at 2:02 PM, prince [prince@qburst.com](mailto:prince@qburst.com) wrote:

> Hi Radu,
> 
> But what I need is to search is really "analyzed", because if content is  
> something like '#sachin big news, retires from ODI', it should get that on  
> searching, but if it is like 'sachin, you are awesome', it should not get  
> that on searching.
> 
> "not\_analyzed" will get only exact matches and is not useful for my usecase  
> (Here, it will get only content with "#sachin" as the full text and not  
> containing "#sachin")
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Elasticsearch-search-fo-words-having-character-tp4037822p4037864.html](http://elasticsearch-users.115913.n3.nabble.com/Elasticsearch-search-fo-words-having-character-tp4037822p4037864.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> 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).

--  
[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

--  
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:** ![prince](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@prince](https://discuss.elastic.co/u/prince)\
**Post date:** [July 10, 2013, 12:12pm UTC](https://discuss.elastic.co/t/elasticsearch-search-fo-words-having-character/12737/7 "2013-07-10T12:12:39Z")

</div>

Hi Radu,

I have found this post [http://webcache.googleusercontent.com/search?q=cache:http://www.fullscale.co/blog/2013/03/04/preserving\_specific\_characters\_during\_tokenizing\_in\_elasticsearch.html](http://webcache.googleusercontent.com/search?q=cache:http://www.fullscale.co/blog/2013/03/04/preserving_specific_characters_during_tokenizing_in_elasticsearch.html)

My mapping, right now, is like this:

{  
"content": {"type": 'string', "index": "analyzed'}  
}

I am not sure how this mapping for getting strings starting with "#" and "@", should change, as I am new to elasticsearch.

---

<div class="post-metadata">

**Author:** ![prince](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@prince](https://discuss.elastic.co/u/prince)\
**Post date:** [July 10, 2013, 12:45pm UTC](https://discuss.elastic.co/t/elasticsearch-search-fo-words-having-character/12737/8 "2013-07-10T12:45:03Z")

</div>

Hi Radu,

I am using elasticsearch for searching a table of selected twitter posts, and we have a UI, that allows users to search for multiple terms using OR condition and we need to display the count of records for each term. We are using the facet for getting the count of individual terms. So, it is not limited to hashtags, but for anything the users searches.

So, is there a better way than using facets to get this count?

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [July 10, 2013, 1:57pm UTC](https://discuss.elastic.co/t/elasticsearch-search-fo-words-having-character/12737/9 "2013-07-10T13:57:13Z")

</div>

Hello,

Cool! Then I think you should try that and see how it works for you. I  
thought the whitespace analyzer alone is enough, but maybe it isn't. I  
didn't test it.

I think you should run a test, see how it fits your use-case and if you  
need something more you can always come back here and ask more questions.

Best regards,  
Radu

On Wed, Jul 10, 2013 at 3:12 PM, prince [prince@qburst.com](mailto:prince@qburst.com) wrote:

> Hi Radu,
> 
> I have found this post
> 
> [http://webcache.googleusercontent.com/search?q=cache:http://www.fullscale.co/blog/2013/03/04/preserving\_specific\_characters\_during\_tokenizing\_in\_elasticsearch.html](http://webcache.googleusercontent.com/search?q=cache:http://www.fullscale.co/blog/2013/03/04/preserving_specific_characters_during_tokenizing_in_elasticsearch.html)
> 
> My mapping, right now, is like this:
> 
> {  
> "content": {"type": 'string', "index": "analyzed'}  
> }
> 
> I am not sure how this mapping for getting strings starting with "#" and  
> "@", should change, as I am new to elasticsearch.
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Elasticsearch-search-fo-words-having-character-tp4037822p4037870.html](http://elasticsearch-users.115913.n3.nabble.com/Elasticsearch-search-fo-words-having-character-tp4037822p4037870.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> 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).

--  
[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

--  
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:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [July 10, 2013, 1:59pm UTC](https://discuss.elastic.co/t/elasticsearch-search-fo-words-having-character/12737/10 "2013-07-10T13:59:27Z")

</div>

On Wed, Jul 10, 2013 at 3:45 PM, prince [prince@qburst.com](mailto:prince@qburst.com) wrote:

> Hi Radu,
> 
> I am using elasticsearch for searching a table of selected twitter posts,  
> and we have a UI, that allows users to search for multiple terms using OR  
> condition and we need to display the count of records for each term. We are  
> using the facet for getting the count of individual terms. So, it is not  
> limited to hashtags, but for anything the users searches.
> 
> So, is there a better way than using facets to get this count?

Hmm... I don't see one. If you need counts for all the terms, then you have  
to have memory for all the terms 🙂

I would monitor the cluster with something like  
SPM[http://sematext.com/spm/elasticsearch-performance-monitoring/](http://sematext.com/spm/elasticsearch-performance-monitoring/).  
You'll be able to see how your memory, field cache, etc goes up and down as  
you use Elasticsearch. Then you can tell whether you have enough hardware  
for the dataset and usage you're expecting.

Best regards,  
Radu

--  
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:27am UTC](https://discuss.elastic.co/t/elasticsearch-search-fo-words-having-character/12737/11 "2017-07-06T02:27:10Z")

</div>


