如何使用query_string匹配精确词 [英] How to match exact word using query_string
问题描述
我有一个Elasticsearch字段值 slim
和 extra slim
,如果我搜索苗条
结果是,我得到了个苗条
包含的文档。我想匹配确切的单词。我在查询时使用了 fieldName.keyword
,但是如果该字段包含多个单词,则不起作用。
I have an Elasticsearch field values slim
and extra slim
, If I search for slim
I'm getting extra slim
included documents as a result. I want to match the exact word. I used fieldName.keyword
while querying but It did'nt work if the field has multiple words.
查询我使用的是
{ query_string:{ query:(fit:slim)}}
如何使用query_string仅匹配指定的值?
How to match only specified value using query_string?
推荐答案
When looking for exact match against a field use term query on keyword
field.
查询:
{
"query": {
"term": {
"fit.keyword": "slim"
}
}
}
更新:通过 query_string
UPDATE: Via query_string
要使用 query_string
进行精确匹配,请包装字符串
For exact match using query_string
wrap the string to be matched in quotes.
{
"query": {
"query_string": {
"query": "fit.keyword:\"extra slim\""
}
}
}
这篇关于如何使用query_string匹配精确词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!