小编Bra*_*rad的帖子

如何在弹性搜索中匹配每个数组项的多个字段

我正在尝试创建一个弹性搜索查询来匹配数组内对象内的多个字段。

例如,我正在查询的 Elastic Search 结构类似于以下内容:

"hits": [
            {
                "_index": "titles",
                "_type": "title",
                ...
                "_source": {
                    ...
                    "genres": [
                        {
                            "code": "adventure",
                            "priority": 1
                        },
                        {
                            "code": "action",
                            "priority": 2
                        },
                        {
                            "code": "horror",
                            "priority": 3
                        }
                    ],
                    ...
                },
                ...
        ]
Run Code Online (Sandbox Code Playgroud)

我想做的是匹配具有特定类型/优先级配对的标题。例如,我尝试将所有标题与code=actionand匹配priority=1,但我的查询返回太多结果。在此示例中,由于流派列表包含与 匹配的流派以及code=action另一个与 匹配的流派,因此出现了上述标题priority=1。我的查询类似于以下内容:

    "query": {
        "bool": {
            "filter": [
                {
                    "bool": {
                        "must":[
                            {"term": {
                                    "genres.code": {
                                        "value": "action",
                                        "boost": 1.0
                                    }
                            }},
                            {"term": {
                                    "genres.priority": {
                                        "value": 1,
                                        "boost": 1.0 …
Run Code Online (Sandbox Code Playgroud)

json elasticsearch

3
推荐指数
1
解决办法
3837
查看次数

标签 统计

elasticsearch ×1

json ×1