Search string in a text

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.

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.

Cheers,
Tim

1 Like

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.

What is the mapping for the field?

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

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?

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.

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

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