使用结合AND,OR和引号的关键字进行搜索查询

时间:2019-06-05 13:23:40

标签: php elasticsearch

我正在使用Elasticsearch搜索引擎,我有关键字和排除关键字。

我想在我的两个输入中使用引号,AND和OR进行高级搜索。

这就是我要尝试的:

关键字:

"foo bar" AND lorem OR ipsum
{
    "body": {
        "query": {
            "bool": {
                "should": [
                    {
                        "bool": {
                            "must": [
                                {
                                    "multi_match": {
                                        "query": "foo bar",
                                        "type": "phrase",
                                        "fields": [
                                            "content",
                                            "title"
                                        ]
                                    }
                                },
                                {
                                    "multi_match": {
                                        "query": "lorem",
                                        "fields": [
                                            "content",
                                            "title"
                                        ]
                                    }
                                }
                            ]
                        }
                    },
                    {
                        "bool": {
                            "must": [
                                {
                                    "multi_match": {
                                        "query": "ipsum",
                                        "fields": [
                                            "content",
                                            "title"
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    }
}

结果:

"lorem foo bar"  => true
"foo bar"  => false
"ipsum foo bar"  => true

它有效,但是正确的方法吗?

对于排除的关键字,我不知道如何在同一系统中添加。

我期望的例子:

排除的关键字:

"test AND test2 OR test3"
"lorem foo bar"  => true
"lorem foo bar test"  => true
"lorem foo bar test3"  => false
"test lorem foo bar test2"  => false

0 个答案:

没有答案
相关问题