2

I have a string field "title"(not analyzed) in elasticsearch. A document has title "Garfield 2: A Tail Of Two Kitties (2006)".

When I use the following json to query, no result returns.

{"query":{"term":{"title":"Garfield 2: A Tail Of Two Kitties (2006)"}}}

I tried to escape the colon character and the braces, like:

{"query":{"term":{"title":"Garfield 2\\: A Tail Of Two Kitties \\(2006\\)"}}}

Still not working.

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
Leon Kennedy
  • 63
  • 3
  • 6

1 Answers1

2

Term query wont tokenize or apply analyzers to the search text. Instead if looks for the exact match which wont work as the string fields are analyzed/tokenized by default.

To give this a better explanation -

Lets say there is a string value as - "I am in summer:camp" When indexing this its broken into tokens as below -

"I am in summer:camp" => [ I , am , in , summer , camp ]

Hence even if you do a term search for "I am in summer:camp" , it wont still work as the token "I am in summer:camp" is not present in the index. Something like phrase query might work better here. Or you can leave "index" field as "not_analyzed" to make sure that string is not tokenized.

Vineeth Mohan
  • 18,633
  • 8
  • 63
  • 77