我正在尝试俱乐部数据的领域,这应该是另一个领域的排序。我还想分页,所以我想我可以使用bucketsort的ElasticSearch。我正面临一个字符串(字母顺序)的问题。
这是我的虚拟数据。
{
"_index": "testing-aggregation",
"_type": "employee",
"_id": "emp001_local000000000000001",
"_score": 10.0,
"_source": {
"name": [
"Person 01"
],
"groupbyid": [
"group0001"
],
"ranking": [
"2.0"
]
}
},
{
"_index": "testing-aggregation",
"_type": "employee",
"_id": "emp002_local000000000000001",
"_score": 85146.375,
"_source": {
"name": [
"Person 02"
],
"groupbyid": [
"group0001"
],
"ranking": [
"10.0"
]
}
},
{
"_index": "testing-aggregation",
"_type": "employee",
"_id": "emp003_local000000000000001",
"_score": 20.0,
"_source": {
"name": [
"Person 03"
],
"groupbyid": [
"group0002"
],
"ranking": [
"-1.0"
]
}
},
{
"_index": "testing-aggregation",
"_type": "employee",
"_id": "emp004_local000000000000001",
"_score": 5.0,
"_source": {
"name": [
"Person 04"
],
"groupbyid": [
"group0002"
],
"ranking": [
"2.0"
]
}
}
上述数据的Map。
{
"name": {
"type": "text",
"fielddata": true,
"fields": {
"lower_case_sort": {
"type": "text",
"fielddata": true,
"analyzer": "case_insensitive_sort"
}
}
},
"ranking": {
"type": "float"
},
"groupbyid": {
"type": "text",
"fielddata": true,
"index": "analyzed",
"fields": {
"raw": {
"type": "keyword",
"index": "not_analyzed"
}
}
}
}
es查询:
{
"from": 0,
"size": 0,
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "name:XYZ"
}
}
]
}
},
"aggregations": {
"groupbyid": {
"terms": {
"field": "groupbyid.raw",
"size": 100
},
"aggs": {
"top_hit_agg": {
"top_hits": {
"size": 100
}
},
"ranking_agg": {
"min": {
"field": "ranking"
}
},
"test_bucket_sort": {
"bucket_sort": {
"sort": [
{
"ranking_agg": {
"order": "desc"
}
}
],
"size": 100,
"from": 0
}
}
}
}
}
}
我能够实现的数字领域。但我不知道我该怎么做的名称字段。一种方法是使用脚本,但我不想使用这种方法,因为它可能是一个昂贵的操作。
有人能帮我吗?我使用的是es 7.7.1。
谢谢你,沙维尔·沙阿
1条答案
按热度按时间xdnvmnnf1#
如果你想分类
name
按字母顺序输入字段,然后代替groupbyid
你可以用name.keyword
在关键字上进行聚合和排序。您不能使用
name
最小聚合中的字段,因为最小聚合不支持文本字段搜索结果: