gpt4 book ai didi

elasticsearch - simple_query_string 和 query_string 哪个更好?

转载 作者:行者123 更新时间:2023-12-02 22:22:03 27 4
gpt4 key购买 nike

simple_query_string有什么区别和 query_string在 Elasticsearch 中?

哪个更适合搜索?

在 Elasticsearch simple_query_string文档,它们是写的

Unlike the regular query_string query, the simple_query_string query will never throw an exception and discards invalid parts of the query.



但不清楚。哪一个更好?

最佳答案

没有简单的答案。这取决于 :)

一般情况下 query_string 专用于更高级的用途。它有更多选项,但正如您所引用的那样,当发送的查询无法作为一个整体进行解析时,它会引发异常。相反 simple_query_string 选项较少,但不会对无效部分抛出异常。

作为一个例子,看看下面的两个查询:

GET _search
{
"query": {
"query_string": {
"query": "hyperspace AND crops",
"fields": [
"description"
]
}
}
}

GET _search
{
"query": {
"simple_query_string": {
"query": "hyperspace + crops",
"fields": [
"description"
]
}
}
}

两者是等效的,并且从您的索引返回相同的结果。但是什么时候你会中断查询并发送:
GET _search
{
"query": {
"query_string": {
"query": "hyperspace AND crops AND",
"fields": [
"description"
]
}
}
}

GET _search
{
"query": {
"simple_query_string": {
"query": "hyperspace + crops +",
"fields": [
"description"
]
}
}
}

然后您将仅从第二个 ( simple_query_string ) 中获得结果。第一个( query_string )会抛出这样的东西:
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "Failed to parse query [hyperspace AND crops AND]",
"index_uuid": "FWz0DXnmQhyW5SPU3yj2Tg",
"index": "your_index_name"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
...
]
},
"status": 400
}

希望您现在了解抛出/不抛出异常的区别。

哪个更好?如果您想将搜索公开给一些普通的最终用户,我宁愿建议使用 simple_query_string .多亏了这一点,最终用户即使在查询中犯了错误,也会在每个查询案例中得到一些结果。 query_string建议一些更高级的用户使用,他们将接受正确查询语法的培训,以便他们知道为什么在每种特定情况下都没有任何结果。

关于elasticsearch - simple_query_string 和 query_string 哪个更好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53076255/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com