我是ElasticSearch的新手,并尝试将其用于数据,其中一个人可以搜索某些文本(例如entity.name)并在结果列表上应用排序。
以下是我的映射:
{
"entity": {
"dynamic_templates": [
{ "text_custom_field_template": {
"match": "ltd_text_*",
"mapping": {
"type": "text"
}
}}
],
"properties": {
"id": {
"type": "long",
"index": "not_analyzed"
},
"treeId": {
"type": "long",
"index": "not_analyzed"
}
"entity.name": {
"type": "text",
"fielddata": true,
"fields": {
"sort": {
"type": "keyword",
"ignore_above": 256
}
}
}
"entity.url": {
"type": "text"
},
"entity.details": {
"type": "text"
}
}
}
}
id name details is_marked
13 ABC entity details 1
14 BCD entity details 1
15 DEF entity details 1
16 EFG entity details 1
17 GHI details 1
18 Untitled entity details 1
我想搜索名称中包含实体的所有实体,然后按字母顺序对结果进行排序。 如果我在弹性搜索下面运行,我得到的结果是asc和desc:
{
"query":{
"multi_match":{
"query":"entity",
"fields":[
"entity.details^1.0",
"entity.name^4.0",
],
"type":"best_fields",
"operator":"AND",
"slop":0,
"prefix_length":0,
"max_expansions":50,
"lenient":false,
"zero_terms_query":"NONE",
"boost":1.0
}
},
"sort":{
"entity.name.sort" : "asc"
}
}
Result :
BCD
EFG
GHI
Untitled
ABC
还有一种方法可以支持相同(搜索和排序)新的自定义文本类型字段,可以由客户端添加吗?