找出在多重匹配查询中匹配的字段 [英] Find out which fields matched in a multi match query

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

问题描述

我在三个字段上使用典型的多重匹配查询:名称,城市,州。多匹配查询也使用Java函数分数脚本。有什么方法可以在得分脚本中知道什么字段匹配我的多匹配查询?如果没有,有没有办法从SearchResponse对象中得出这个结果?

I am using a typical multi match query on three fields: name, city, state. The multi match query is also using a Java function score script. Is there any way to know in the score script what fields matched my multi match query? If not, is there any way to figure this out from the SearchResponse object?

我目前正在使用Elasticsearch 1.2.1,但如果有必要,我可以轻松升级。 p>

I am currently on Elasticsearch 1.2.1 but I can easily upgrade if it's necessary.

推荐答案

我不相信你可以直接使用多重匹配来做到这一点,但是如果你添加突出显示,你应该得到一个回应,显示哪个匹配的字段:

I don't believe you can do this directly with just multi match, but if you add highlighting you should get a response showing which fields matched:

http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/highlighting-intro.html

在该页面的示例:

    GET /megacorp/employee/_search
    {
        "query" : {
            "match_phrase" : {
                "about" : "rock climbing"
            }
        },
        "highlight": {
            "fields" : {
                "about" : {}
            }
        }

}

您可以将match_phrase更改为multi_match并添加字段列表:

you would change the match_phrase to a multi_match and add the field list:

    GET /megacorp/employee/_search
    {
        "query" : {
            "multi_match" : {
                "query" : "rock climbing",
                "fields": ["about", "otherfield"]
            }
        },
        "highlight": {
            "fields" : {
                "about" : {},
                 "otherfield": {}
            }
        }

}

这应该会让你有一个高亮反应,其中包括匹配文字和匹配的字段。

and that should get you a highlight response which includes the highlight around the matching text and the field that was matched.

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

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