stp*_*tpk 18 nested match nested-properties elasticsearch
所以我的问题基本上和这里描述的一样,但是对于小组来说仍然没有答案.
我的映射:
{
"abstract": {
"properties": {
"summary": {
"type": "string"
}
}
},
"authors": {
"type": "nested",
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想对这两个领域进行全文搜索,可能是不平等的加权.我想到的查询,但不幸的是不起作用,将是这样的:
{
"query": {
"bool": {
"should": [{
"multi_match": {
"query": "higgs boson",
"fields": ["abstract.summary^5", "author.last_name^2"]
}
}]
}
}
}
Run Code Online (Sandbox Code Playgroud)
我没有得到authors字段的任何结果,因为它的嵌套映射.我也无法摆脱嵌套属性 - 我将它用于聚合.任何优雅的想法如何解决?
Aym*_*ric 11
将映射更改为使用的以下映射include_in_root: true将允许您使用原始写入的查询:
{
"abstract": {
"properties": {
"summary": {
"type": "string"
}
}
},
"authors": {
"type": "nested",
"include_in_root": true,
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可能希望将内部对象索引为嵌套字段和展平对象字段.这可以通过将include_in_parent设置为true来实现.- 链接
注意:include_in_root可能会在将来的elasticsearch版本中弃用copy_to.
stp*_*tpk 10
我设法解决的唯一解决方案,这不是方便,也不优雅,但以某种方式工作是这样的查询:
"query": {
"bool": {
"should": [
{
"nested": {
"path": "authors",
"query": {
"multi_match": {
"query": "higgs",
"fields": ["last_name^2"]
}
}
}
},
{
"multi_match": {
"query": "higgs",
"fields": ["abstract.summary^5"]
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我也不确定增强是否会按预期工作,只要它设置在不同的查询中.任何建议赞赏.
| 归档时间: |
|
| 查看次数: |
10370 次 |
| 最近记录: |