# Search string in a text

**URL:** <https://discuss.elastic.co/t/search-string-in-a-text/135348>\
**Category:** Kibana\
**Created:** [June 11, 2018, 11:12am UTC](https://discuss.elastic.co/t/search-string-in-a-text/135348 "2018-06-11T11:12:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElGreco1520](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@ElGreco1520](https://discuss.elastic.co/u/ElGreco1520)\
**Post date:** [June 11, 2018, 11:12am UTC](https://discuss.elastic.co/t/search-string-in-a-text/135348/1 "2018-06-11T11:12:51Z")

</div>

I have a bar display. I want to add a filter to separate into two groups, depending on whether the text contains a word or not.  
If I put in the filter: SERVICE LIKE '% environment%'. Yes that works, but I would like the other group to be the opposite. NOT SERVICE LIKE '% environment%' and this does not work.

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [June 12, 2018, 6:30am UTC](https://discuss.elastic.co/t/search-string-in-a-text/135348/2 "2018-06-12T06:30:12Z")

</div>

Hi,

I think the reason this is not working, that this is not the real Elasticsearch syntax you are using. Elasticsearch is not a relational database, meaning you can't use SQL there, as you seem trying to achieve. So your query will actually just search for documents containing the words `SERVICE`, `LIKE` or `'% environment%'`. I think in your case actually most will match on 'service'. But that's why actually your "negated" query doesn't work at all anymore as expected.

So you would need to use proper syntax here. If you are actually requiring to search within a field value, you would most likely want to use something like: `service:*environment*` and to filter it out `-service:*environment*` or `NOT service:*environment*`.

This might still be influenced by your actual indexing of the data. I tried to put a summary of how this works in [this blog post](https://www.timroes.de/2016/05/29/elasticsearch-kibana-queries-in-depth-tutorial/).

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![ElGreco1520](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@ElGreco1520](https://discuss.elastic.co/u/ElGreco1520)\
**Post date:** [June 12, 2018, 8:49am UTC](https://discuss.elastic.co/t/search-string-in-a-text/135348/3 "2018-06-12T08:49:53Z")

</div>

Hi timroes,

Thanks for your reply but this does not work for me. Kdahkahkadjh does not return anything and odjalkadjflkjad returns all possible results. Finally I got it in the following way: environment returns the records that contain that word and -environment returns the records that do not contain that word.

I do not know what's happening.

Thanks, Rafa.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 12, 2018, 8:56am UTC](https://discuss.elastic.co/t/search-string-in-a-text/135348/4 "2018-06-12T08:56:42Z")

</div>

What is the mapping for the field?

---

<div class="post-metadata">

**Author:** ![ElGreco1520](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@ElGreco1520](https://discuss.elastic.co/u/ElGreco1520)\
**Post date:** [June 12, 2018, 11:11am UTC](https://discuss.elastic.co/t/search-string-in-a-text/135348/5 "2018-06-12T11:11:59Z")

</div>

It has no mapping. They are data from an unmodified database.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 12, 2018, 11:23am UTC](https://discuss.elastic.co/t/search-string-in-a-text/135348/6 "2018-06-12T11:23:45Z")

</div>

Every field in Elasticsearch has a mapping. If you have not specified any it is typically assigned dynamically. Depending on how the field is mapped, it may or may not be case sensitive. can you try searching for `Kdahkahkadjh` as well as `kdahkahkadjh` and see if that makes a difference?

---

<div class="post-metadata">

**Author:** ![ElGreco1520](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@ElGreco1520](https://discuss.elastic.co/u/ElGreco1520)\
**Post date:** [June 13, 2018, 8:45am UTC](https://discuss.elastic.co/t/search-string-in-a-text/135348/7 "2018-06-13T08:45:25Z")

</div>

The field I want to filter is a string. In discovering it appears with a "t" next to it. Capital letters are not the problem since the word I'm looking for is always lowercase.

Thanks.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 13, 2018, 8:47am UTC](https://discuss.elastic.co/t/search-string-in-a-text/135348/8 "2018-06-13T08:47:42Z")

</div>

I am not sure I understand. Can you please provide a recreation script?

---

<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 11, 2018, 8:47am UTC](https://discuss.elastic.co/t/search-string-in-a-text/135348/9 "2018-07-11T08:47:57Z")

</div>

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