弹性搜索嵌套多匹配查询 [英] Elastic Search nested multimatch query
问题描述
所以我的问题与描述的基本相同 此处,但在该组中仍未得到答复.
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"]
}
}]
}
}
}
由于其嵌套映射,我没有从作者字段中得到任何结果.我也无法摆脱嵌套属性 - 我将它用于聚合.任何优雅的想法如何解决它?
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?
推荐答案
我设法找到的唯一解决方案是这样的查询:
The only solution that I managed to work out, which is not handy nor elegant but somehow works is such query:
"query": {
"bool": {
"should": [
{
"nested": {
"path": "authors",
"query": {
"multi_match": {
"query": "higgs",
"fields": ["last_name^2"]
}
}
}
},
{
"multi_match": {
"query": "higgs",
"fields": ["abstract.summary^5"]
}
}
]
}
}
我也不确定提升是否会按预期工作,前提是它是在不同的查询中设置的.任何建议表示赞赏.
I'm also not sure if the boosting will work as expected, providing it's set in different queries. Any suggestions appreciated.
这篇关于弹性搜索嵌套多匹配查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!