gpt4 book ai didi

elasticsearch - elasticsearch:使应该过滤

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

我想用一个过滤器进行搜索,该过滤器排除不符合条件或其他条件的结果:

我试图对过滤器进行应试,但失败了:

POST /my_index/_search
{
"query": {
"bool": {
"filter": [
{
"should": [
{
"match": {
"type1_title": "searched match"
}
},
{
"match": {
"type2_title": "searched match"
}
}
]
}
]
}
}
}

它引发该错误:
 "error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[should] query malformed, no start_object after query name",
"line": 9,
"col": 21
}
],
"type": "parsing_exception",
"reason": "[should] query malformed, no start_object after query name",
"line": 9,
"col": 21
},
"status": 400
}

您知道我们是否可以执行或过滤器吗?

最佳答案

为什么不简单地使用bool/should,这里就不需要filter

POST /my_index/_search
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"match": {
"type1_title": "searched match"
}
},
{
"match": {
"type2_title": "searched match"
}
}
]
}
}
}

如果您确实想要保留 bool/filter/should构造,则需要这样做:
POST /my_index/_search
{
"query": {
"bool": {
"filter": [
{
"bool": {
"should": [
{
"match": {
"type1_title": "searched match"
}
},
{
"match": {
"type2_title": "searched match"
}
}
]
}
}
]
}
}
}

关于elasticsearch - elasticsearch:使应该过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42276927/

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