2024-05-29 06:02:29 发布
网友
我试图在弹性搜索中查询时匹配整个语句。但无法正确地实现它
"query": { "match_phrase": {"description": query_tokens} }
我尝试使用Air Conditioning, Air Conditioner,但它提供了类似于常规匹配查询的结果。 如何实现完整的语句获取
Air Conditioning, Air Conditioner
解决方案
将这些语句(描述字段)存储在keyword field中
keyword field
不工作的原因
对匹配短语查询进行分析,这意味着在索引时使用相同的分析器,用作创建搜索标记的查询时,默认情况下,text字段的standard analyzer在空间和,id特殊字符上断开标记
text
,
Elasticsearch文档中的声明
The match_phrase query analyzes the text and creates a phrase query out of the analyzed text. For example:
索引定义
{ "mappings": { "properties": { "description": { "type" : "keyword" } } } }
索引样本文档
{ "description" : "Air Conditioning, Air Conditioner" }
搜索查询
{ "query": { "match_phrase" : { "description" : { "query" : "Air Conditioning, Air Conditioner" } } } }
搜索结果
"hits": [ { "_index": "match", "_type": "_doc", "_id": "1", "_score": 0.2876821, "_source": { "description": "Air Conditioning, Air Conditioner" } } ]
解决方案
将这些语句(描述字段)存储在
keyword field
中不工作的原因
对匹配短语查询进行分析,这意味着在索引时使用相同的分析器,用作创建搜索标记的查询时,默认情况下,
text
字段的standard analyzer在空间和,
id特殊字符上断开标记Elasticsearch文档中的声明
索引定义
索引样本文档
搜索查询
搜索结果
相关问题 更多 >
编程相关推荐