简体   繁体   English

使用冒号的Elasticsearch术语查询

[英]Elasticsearch term query with colons

I have a string field "title"(not analyzed) in elasticsearch. 我在elasticsearch中有一个字符串字段“ title”(未分析)。 A document has title "Garfield 2: A Tail Of Two Kitties (2006)". 一份文件的标题为“加菲猫2:两只小猫的尾巴(2006年)”。

When I use the following json to query, no result returns. 当我使用以下json查询时,没有结果返回。

{"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. 还是行不通。 I am stuck here. 我被困在这里。 Could anyone help me out? 有人可以帮我吗?

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. 或者,您可以将“ index”字段保留为“ not_analyzed”,以确保未对字符串进行标记化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM