我在测绘中有这样的字段:
"computedCompanyName": {
"type": "text",
"fields": {
"exact": {
"type": "text",
"analyzer": "exact"
},
"phon": {
"type": "text",
"analyzer": "phonetic"
}
}
}
此名称是通过使用某些业务逻辑计算出来的,这就是它在索引中命名为计算名称并存储为该名称的原因。用于计算此名称的部分不会出现在索引中。
我想按此字段对公司进行排序。如您所见,此属性有两种表示形式:精确和语音。因此,根据用户的选择,我将按精确或语音表示进行排序。例如,Mötor和Moetor是两个表示,sortField可以如下所示:
private SearchQuery createDefaultSortingConditions(NativeSearchQueryBuilder nativeSearchQueryBuilder) {
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("computedCompanyName.exact").order(SortOrder.ASC));
return nativeSearchQueryBuilder.build();
}
因此,在上面的查询中,我将按computedCompanyName的精确表示对文档进行排序,但我还希望实现computedCompanyName. phonsortField。
问题是,当我执行这个命令时,我得到了(什么是Fielddata?为什么我得到这个错误?):顺便说一句:这个字段也必须是可搜索的,这取决于用户是否选择精确/语音搜索,他想搜索其精确或语音表示。
Suppressed: org.elasticsearch.client.ResponseException: method [POST], host [http://localhost:9200], URI [/my_test/my/_search?rest_total_hits_as_int=true&typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&ignore_throttled=true&search_type=dfs_query_then_fetch&batched_reduce_size=512], status line [HTTP/1.1 400 Bad Request]
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [computedCompanyName.exact] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"dfs","grouped":true,"failed_shards":
更重要的是..当我改变一切关键字类型,并试图排序,然后我有问题的分析器,应该工作的搜索目的。
Suppressed: org.elasticsearch.client.ResponseException: method [PUT], host [http://localhost:9200], URI [/rt_test/_mapping/rechtstraegerindexeddata?master_timeout=30s&include_type_name=true&timeout=30s], status line [HTTP/1.1 400 Bad Request]
Warnings: [[types removal] Specifying types in put mapping requests is deprecated. To be compatible with 7.0, the mapping definition should not be nested under the type name, and the parameter include_type_name must be provided and set to false.]
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Mapping definition for [fields] has unsupported parameters: [search_analyzer : phonetic] [analyzer : phonetic]"}],"type":"mapper_parsing_exception","reason":"Mapping definition for [fields] has unsupported parameters: [search_analyzer : phonetic] [analyzer : phonetic]"},"status":400}
at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:936)
是否可以使用分析器按字段排序?如果可以,我可以使用相同的computedCompanyName进行搜索和排序吗?
1条答案
按热度按时间kxkpmulp1#
我认为最好的选择是为新Map重新索引索引索引,如下所示:
这样你就可以使用分析器对你的搜索和使用“computedCompanyName.keyword”进行排序。