【发布时间】:2017-06-02 17:53:39
【问题描述】:
我正在尝试在嵌套查询的点击中返回突出显示。根据文档,这是可能的。文档说:
父/子和嵌套功能允许返回在不同范围内具有匹配项的文档。在嵌套情况下,根据嵌套内部对象中的匹配返回文档。 内部命中功能返回搜索响应中的每个搜索命中附加嵌套命中,这些命中导致搜索命中在不同范围内匹配。 可以通过在嵌套、has_child 或 has_parent 查询和过滤器上定义 inner_hits 定义来使用内部命中。 内部点击还支持以下每个文档的功能:
'Highlighting'、'Explain Source'、'filtering'、'Script fields'、'Doc value'、'fields'、'Include versions'。
但是,根据以下映射和查询,我无法使其正常工作。谁能解释我出错的原因和位置?
注意:我专门指的是嵌套类型,而不是 parent_child。
我发现它仅在将 referenceIdValue 和 ReferenceIdType 从关键字更改为文本时才有效,但显然这不是我想要的。 ES 文档说:
"字段名称支持通配符表示。例如,使用comment_*将导致所有匹配表达式的文本和关键字字段(以及5.0之前版本的字符串)突出显示。请注意,所有其他字段都不会突出显示。 " https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html#_highlight_query我在想这可能是一个错误?
非常感谢。
映射:
{
"entity": {
"dynamic_templates": [{
"catch_all": {
"match_mapping_type": "*",
"mapping": {
"type": "text",
"store": true,
"analyzer": "phonetic_index",
"search_analyzer": "phonetic_query"
}
}
}],
"_all": {
"enabled": false
},
"properties": {
"entityName": {
"type": "text",
"store": true,
"analyzer": "indexed_index",
"search_analyzer": "indexed_query",
"referenceIds": {
"type": "nested",
"properties": {
"referenceIdValue": {
"type": "keyword",
"norms": true,
"store": true
},
"referenceIdType": {
"type": "keyword",
"store": true,
"norms": true
}
}
},
"isPublished": {
"type": "boolean",
"store": true
}
}
}
}
查询:
curl -XGET "127.0.0.1:9200/test/entity/_search?pretty" -d"
{
"query": {
"bool": {
"filter": {
"term": {
"isPublished": "true"
}
},
"must": [
[{
"nested": {
"query": {
"bool": {
"must": [
[{
"term": {
"referenceIds.referenceIdValue": "123456"
}
}, {
"term": {
"referenceIds.referenceIdType": "ENCO"
}
}]
]
}
},
"inner_hits": {
"highlight": {
"fields": {
"referenceIds.referenceIdValue": {},
"referenceIds.referenceIdType": {}
}
}
},
"path": "referenceIds"
}
}]
]
}
}
}"
结果:
{
"took": 99,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 14.319202,
"hits": [{
"_index": "test",
"_type": "entity",
"_id": "3423631",
"_score": 14.319202,
"_source": {
"entityName": "Test Entity",
"referenceIds": [{
"referenceIdValue": "AAAABBBB",
"referenceIdType": "SULA"
}, {
"referenceIdValue": "123456",
"referenceIdType": "ENCO"
}]
},
"inner_hits": {
"referenceIds": {
"hits": {
"total": 1,
"max_score": 14.319202,
"hits": [{
"_nested": {
"field": "referenceIds",
"offset": 3
},
"_score": 14.319202,
"_source": {
"referenceIdValue": "123456",
"referenceIdType": "ENCO"
}
}]
}
}
}
}]
}
}
【问题讨论】:
标签: elasticsearch