0

I want to search a pharse in Elasticsearch for exact match. But Elasticsearch giving other containing pharses too.

An example; I want to search for "little cat", but Elasticsearch returns "little cat jump", "little cats", "little cat saved the baby from death", etc...

I just want exact and only "little cat", not the others. How can I do this query?

My contents like;

{
    title: "little cat",
    content: "bla bla bla"
},
...
musa
  • 1,457
  • 18
  • 37

2 Answers2

1

It depends a lot on how title is indexed. For such a requirement, title would need to be analyzed as keyword, meaning whatever text is in title exactly like that is put in ES' internal Lucene inverted index.

And a term filter would be the choice for searching little cat in title analyzed as keyword.

If you want to have other operations made to your title field at indexing time, you can add a filter, for example for lowercasing any upper-case letters. But, in any case, you DO need a keyword analyzer.

If you don't want to change how title is being indexed now, you can make it as multi_field and add a title_keyword (for example) field that should be indexed using your keyword analyzer.

Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89
0

When indexing string fields, default mapping index type for strings is analyzed (like a full text index on MySQL). You should recreate the mapping and set index type to not_analyzed.

Look this for more about Core Types and mapping