flex 搜寻7.9
我正在通过文本框搜索通过Web UI向用户显示的单个字段。
{
match: {
body: {
query: 'beer pretzels',
}
}
}
我正在辩论是否使用simple_query_string
代替。 {
simple_query_string: {
query: 'beer pretzels',
}
}
我最初的想法是,如果我在关键字中检测到特殊字符,则切换到simple_query_string
。但是现在我不知道为什么要使用match
了。我的问题:
对于关键字不包含特殊字符的简单情况,
match
和simple_query_string
之间有什么区别吗?有什么理由为什么我不会一直使用
simple_query_string
?
最佳答案
Simple Query string returns documents based on a provided query string, using a parser with a limited but fault-tolerant syntax.
引用它以获得detailed explanation,它指出:
The simple_query_string query is a version of the query_string query that is more suitable for use in a single search box that is exposed to users because it replaces the use of AND/OR/NOT with +/|/-, respectively, and it discards invalid parts of a query instead of throwing an exception if a user makes a mistake.
它支持Lucene语法来解释文本,您可以引用此article来提供有关简单查询字符串如何工作的详细信息。
Match Query returns documents that match a provided text, number, date or boolean value. The provided text is analyzed before matching.
引用此ES documentation part和此blog,以了解匹配查询的工作方式
我尝试使用简单查询字符串和匹配查询在搜索查询下面运行此查询:
索引数据
{
"content":"foo bar -baz"
}
使用简单查询字符串进行搜索查询:{
"query": {
"simple_query_string": {
"fields": [ "content" ],
"query": "foo bar -baz"
}
}
}
搜索结果:"hits": [
{
"_index": "stof_63937563",
"_type": "_doc",
"_id": "1",
"_score": 0.5753642, <-- note this
"_source": {
"content": "foo bar -baz"
}
}
]
使用匹配查询的搜索查询:{
"query": {
"match": {
"content": {
"query": "foo bar -baz"
}
}
}
}
搜索结果:"hits": [
{
"_index": "stof_63937563",
"_type": "_doc",
"_id": "1",
"_score": 0.8630463, <-- note this
"_source": {
"content": "foo bar -baz"
}
}
]
请引用此SO answer,它解释了multi_match
和query_string
之间的区别
关于elasticsearch - 如果没有特殊字符, “match”和 “simple_query_string”之间有区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63937563/