Pra*_*Dey 2 elasticsearch kibana
{
"parent" : "some_id",
"type" : "support",
"metadata" : {
"account_type" : "Regular",
"subject" : "Test Subject",
"user_name" : "John Doe",
"origin" : "Origin",
"description" : "TEST",
"media" : [ ],
"ticket_number" : "XXXX",
"status" : "completed",
},
"create_time" : "2021-02-24T15:08:57.750Z",
"entity_name" : "comment"
}
Run Code Online (Sandbox Code Playgroud)
这是我的演示数据。当我尝试按metadata.sort排序时,例如->
GET comments-*/_search
{
"query": {
"bool": {
"must": [{
"match": {
"type": "support"
}
}]
}
},
"from": 0,
"size": 50,
"sort": [{
"metadata.status": {
"order": "desc"
}
}]
}
Run Code Online (Sandbox Code Playgroud)
它说 ->默认情况下在文本字段上禁用字段数据。在 [metadata.status] 上设置 fielddata=true 以便通过反转倒排索引将 fielddata 加载到内存中。但请注意,这可能会使用大量内存。或者使用关键字字段。
我不知道如何实现同样的目标,因为我对 ESS 很陌生。任何帮助,将不胜感激
您只能在字符串字段上按“关键字”类型的字段进行排序。
如果您在发送文档之前未设置映射,Elasticsearch 动态映射将创建 2 个字段。
在本例中为“status”和“status.keyword”。
因此,请尝试使用“metadata.status.keyword”。
长话短说
对于不进行全文搜索的字段(如状态标志),最好只存储字段的关键字版本。
为此,您必须在对任何文档建立索引之前设置映射。
有一个技巧:
POST test_predipa/_doc
{
"parent" : "some_id",
"type" : "support",
"metadata" : {
"account_type" : "Regular",
"subject" : "Test Subject",
"user_name" : "John Doe",
"origin" : "Origin",
"description" : "TEST",
"media" : [ ],
"ticket_number" : "XXXX",
"status" : "completed"
},
"create_time" : "2021-02-24T15:08:57.750Z",
"entity_name" : "comment"
}
Run Code Online (Sandbox Code Playgroud)
GET test_predipa/_mapping
Run Code Online (Sandbox Code Playgroud)
PUT test_predipa_new
{
"mappings": {
"properties": {
"create_time": {
"type": "date"
},
"entity_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"metadata": {
"properties": {
"account_type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"description": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"origin": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"status": {
"type": "keyword"
},
"subject": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"ticket_number": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"user_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"parent": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
POST _reindex
{
"source": {
"index": "test_predipa"
},
"dest": {
"index": "test_predipa_new"
}
}
Run Code Online (Sandbox Code Playgroud)
GET test_predipa_new/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"type": "support"
}
}
]
}
},
"from": 0,
"size": 50,
"sort": [
{
"metadata.status": {
"order": "desc"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10464 次 |
| 最近记录: |