Elastic Search嵌套多重匹配查询 [英] Elastic Search nested multimatch query

查看:346
本文介绍了Elastic Search嵌套多重匹配查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的问题与

So my problem is basically the same as described here, however it still remains unanswered on the group.

我的映射:

{
    "abstract": {
        "properties": {
            "summary": {
                "type": "string"
            }
        }
    },
    "authors": {
        "type": "nested",
        "properties": {
            "first_name": {
                "type": "string"
            },
            "last_name": {
                 "type": "string"
            }
        }
    }
}

我想对这两个字段进行全文搜索,可能加权不均.我想到的查询是这样的,但不幸的是它不起作用:

And I would like to perform a full-text search on both of these fields, probably unequally weighted. The query that comes to my mind, but unfortunately doesn't work, would be this:

{
    "query": {
        "bool": {
            "should": [{
                "multi_match": {
                    "query": "higgs boson",
                    "fields": ["abstract.summary^5", "author.last_name^2"]
                }
            }]
        }
    }
}

由于其嵌套映射,我无法从authors字段获得任何结果.我也无法摆脱嵌套属性-我将其用于聚合.有什么绝妙的主意如何解决吗?

I don't get any results from the authors field, because of its nested mapping. I also can't get rid of the nested property - I use it for aggregations. Any elegant idea how to solve it?

推荐答案

将映射更改为以下使用include_in_root: true的映射,将允许您使用原始编写的查询:

Changing your mapping to the following one which uses include_in_root: true will allow you to use the query you original wrote:

{
    "abstract": {
        "properties": {
            "summary": {
                "type": "string"
            }
        }
    },
    "authors": {
        "type": "nested",
        "include_in_root": true,
        "properties": {
            "first_name": {
                "type": "string"
            },
            "last_name": {
                 "type": "string"
            }
        }
    }
}

您可能希望将内部对象索引为嵌套字段和展平的对象字段.这可以通过将include_in_parent设置为true来实现. -链接

注意:include_in_root可能会在以后的Elasticsearch版本中弃用,而取而代之的是copy_to.

Note: include_in_root may be deprecated in future versions of elasticsearch in favor of copy_to.

这篇关于Elastic Search嵌套多重匹配查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆