php - ES:匹配 bool 值和模糊查询

标签 php database laravel elasticsearch nosql

我有ES查询。现在,我想向此查询添加“模糊”参数。
我在尝试 :

            "body"  : {
            "query" : {
                "bool" : {
                    "must" : {
                        $finalQuery,
                        },
                    }
                },
                "match" : {
                    "city" : {
                        "query" : 'Tokkiio',
                        "fuzziness" : "AUTO"
                    },
                }
            }

$finalQuery is query generated in loop, contains terms, range and term parameters.



我收到:
"{"error":{"root_cause":[{"type":"parsing_exception","reason":"[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":177}],"type":"parsing_exception","reason":"[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":177},"status":400}"

感谢帮助。

最佳答案

请按照此处https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html的说明将查询重组为查询上下文和过滤上下文。

将模糊查询和类似条件放在查询上下文中。移动范围和任何过滤条件以过滤上下文。这是一个示例查询。

{
    "query":
    {
        "bool":
        {
            "must":
            {
                "fuzzy":
                {
                    "city":
                    {
                        "value": "Tokkiio",
                        "fuzziness": "AUTO"
                    }
                }
            },
            "filter":
            {
                "range":
                {
                    "year":
                    {
                        "gte": 2016
                    }
                }
            }
        }
    }
}

关于php - ES:匹配 bool 值和模糊查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51863076/

相关文章:

database - DB2 和 Oracle 之间的差异

php - 如何在 PhpStorm 9 for Blade 模板中使变量自动完成?

php - 我如何从给定的日期时间结构创建碳对象?

php - 使用 Youtube Api v3 和 oauth2 无需用户身份验证即可将视频上传到我的 Youtube channel

php - 为什么此表单不返回结果?

用于空测试的 PHPUnit 占位符

java - 以动态方式计算双变量的平均值

laravel - Laravel 5 Crypt 函数中预期的字符长度

php - Laravel:在 DB::raw() 中使用别名时未知列

php - Eloquent 仅获取一列作为数组