尝试从第二个索引的runtime_mapping“lookup”值中对值进行排序。如果去掉排序,我就可以看到值。尝试过直接排序和使用各种无痛排序脚本。这是不是还没有准备好黄金时间(添加v8.2)或有什么我做错了?
下面是父索引:
{
"oir_pr_lh_2021": {
"mappings": {
"properties": {
"subToiId": {
"type": "integer"
}
}
}
}
}
以下是查找索引:
{
"sub_toi_lk": {
"mappings": {
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "keyword"
}
}
}
}
}
以下是显示查找工作的搜索:
{
"runtime_mappings": {
"subToiLk": {
"type": "lookup",
"target_index": "sub_toi_lk",
"input_field": "subToiId",
"target_field": "id",
"fetch_fields": [
"name"
]
}
},
"fields": [
"subToiId",
"subToiLk"
],
"_source": false
}
部分结果:
{
"hits": {
"total": {
"value": 14,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "oir_pr_lh_2021",
"_id": "1423949",
"_score": 1,
"fields": {
"subToiLk": [
{
"name": [
"Individual Medicare Supplement - Medicare Select"
]
}
],
"subToiId": [
732
]
}
}
]
}
}
现在尝试排序:
{
"runtime_mappings": {
"subToiLk": {
"type": "lookup",
"target_index": "sub_toi_lk",
"input_field": "subToiId",
"target_field": "id",
"fetch_fields": [
"name"
]
}
},
"sort": {
"_script": {
"type": "string",
"script": {
"lang": "painless",
"source": "doc['subToiLk.name'].value"
},
"order": "asc"
}
},
"fields": [
"subToiId",
"subToiLk"
],
"_source": false
}
退货:
{
"shard": 0,
"index": "oir_pr_lh_2021",
"node": "ka3YrBmnRCSxjD0eF60KXw",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.server@8.5.0/org.elasticsearch.search.lookup.LeafDocLookup.getFactoryForDoc(LeafDocLookup.java:127)",
"org.elasticsearch.server@8.5.0/org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:171)",
"org.elasticsearch.server@8.5.0/org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:32)",
"doc['subToiLk.name'].value",
" ^---- HERE"
],
"script": "doc['subToiLk.name'].value",
"lang": "painless",
"position": {
"offset": 4,
"start": 0,
"end": 26
},
"caused_by": {
"type": "illegal_argument_exception",
"reason": "No field found for [subToiLk.name] in mapping"
}
}
}
将“脚本”更改为:
{
"script": {
"lang": "painless",
"source": "doc['subToiLk'].value"
}
}
退货
{
"shard": 0,
"index": "oir_pr_lh_2021",
"node": "ka3YrBmnRCSxjD0eF60KXw",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.server@8.5.0/org.elasticsearch.index.mapper.MappedFieldType.fielddataBuilder(MappedFieldType.java:101)",
"org.elasticsearch.server@8.5.0/org.elasticsearch.index.fielddata.IndexFieldDataService.getForField(IndexFieldDataService.java:102)",
"org.elasticsearch.server@8.5.0/org.elasticsearch.index.query.SearchExecutionContext.lambda$lookup$2(SearchExecutionContext.java:500)",
"org.elasticsearch.server@8.5.0/org.elasticsearch.search.lookup.SearchLookup.getForField(SearchLookup.java:114)",
"org.elasticsearch.server@8.5.0/org.elasticsearch.search.lookup.LeafDocLookup$2.run(LeafDocLookup.java:136)",
"org.elasticsearch.server@8.5.0/org.elasticsearch.search.lookup.LeafDocLookup$2.run(LeafDocLookup.java:132)",
"java.base/java.security.AccessController.doPrivileged(AccessController.java:318)",
"org.elasticsearch.server@8.5.0/org.elasticsearch.search.lookup.LeafDocLookup.getFactoryForDoc(LeafDocLookup.java:132)",
"org.elasticsearch.server@8.5.0/org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:171)",
"org.elasticsearch.server@8.5.0/org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:32)",
"doc['subToiLk'].value",
" ^---- HERE"
],
"script": "doc['subToiLk'].value",
"lang": "painless",
"position": {
"offset": 4,
"start": 0,
"end": 21
},
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Fielddata is not supported on field [subToiLk] of type [lookup]"
}
}
}
使用一个简单的sort语句:
{
"sort": [
"subToiLk.name"
],
}
返回此错误:
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "No mapping found for [subToiLk.name] in order to sort on",
"index_uuid": "eKAO5aYJQuKMK3t1ZaOPcQ",
"index": "oir_pr_lh_2021"
}
]
}
}
1条答案
按热度按时间sczxawaw1#
由类型为lookup的运行时字段检索的字段可用于丰富搜索响应中的命中。无法对这些字段进行查询或聚合。