【发布时间】:2019-05-18 13:01:30
【问题描述】:
这是我的示例数据集,
{
"parent":[
{
"name":"John Doe 1",
"age":"100 year",
"sex":"male",
"child":[
{
"name":"Jane Doe 1",
"height":100.00,
"width":100.00
},
{
"name":"Jane Doe 2",
"height":100.00,
"width":100.00
}
]
},
{
"name":"John Doe 2",
"age":"100 year",
"sex":"male",
"child":[
{
"name":"Jane Doe 3",
"height":100.00,
"width":100.00
},
{
"name":"Jane Doe 4",
"height":100.00,
"width":100.00
}
]
}
]
}
我的定义:
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"default": {
"type": "simple"
}
}
}
}
},
"mappings": {
"_doc": {
"properties": {
"parent": {
"type": "nested",
"properties": {
"name": {
"type": "keyword"
},
"age": {
"type": "text"
},
"sex": {
"type": "text"
},
"child": {
"type": "nested",
"properties": {
"name": {
"type": "text"
},
"height": {
"type": "float"
},
"width": {
"type": "float"
}
}
}
}
}
}
}
}
}
我正在使用以下查询来查找 parent.name 属性中的匹配项,并且可以获得亮点。
{
"query": {
"bool": {
"should": [
{
"nested": {
"inner_hits": {
"highlight": {
"fields": {
"parent.name": {}
},
"number_of_fragments": 0,
"pre_tags": [
"<span>"
],
"post_tags": [
"</span>"
]
}
},
"path": "parent",
"query": {
"bool": {
"must": [
{
"match": {
"parent.name": {
"query": "John",
"fuzziness": "AUTO:3,6",
"prefix_length": "0"
}
}
}
]
}
}
}
}
],
}
},
"_source": ["parent"],
"sort": [
{
"_score": {
"order": "desc"
}
},
{
"createdOn": {
"order": "desc"
}
}
]
}
有没有办法在 child.name 属性中获得匹配的内联高亮显示,以便轻松找到对应数组的哪个元素被匹配?
例如,对于给定的样本数据,如果我按“Doe”搜索,我预计会得到 6 个命中,而如果按“Jane”搜索,我只会得到 4 个。
【问题讨论】:
-
你想要匹配
parent.nameANDchild.name或者你想要做 ORing。任何一个都应该匹配? -
是的,任何一个都应该匹配。例如,如果我按“Doe”搜索,我预计会得到 6 个命中,而如果我按“Jane”搜索,我只会得到 4 个。
标签: elasticsearch