返回一条记录每个产品在Kibana,我可以为各种产品(product.name)与时间戳和其他信息一起查看日志。以下是日志之一:ELK查询与最大时间戳
{
"_index": "xxx-2017.08.30",
"_type": "logs",
"_id": "xxxx",
"_version": 1,
"_score": null,
"_source": {
"v": "1.0",
"level": "INFO",
"timestamp": "2017-01-30T18:31:50.761Z",
"product": {
"name": "zzz",
"version": "2.1.0-111"
},
"context": {
...
...
}
},
"fields": {
"timestamp": [
1504117910761
]
},
"sort": [
1504117910761
]
}
还有几个其他日志用于同一产品,还有几个不同产品的日志。
不过,我想写,对于给定product.name(具有最大时间戳值)返回单个记录查询并返回所有其他产品相同的信息。那就是每个产品和每个产品都有一个日志返回,它应该是具有最大时间戳的日志。
我该如何做到这一点?
我试图按照中列出的方法: How to get latest values for each group with an Elasticsearch query?
并创建一个查询:
{
"aggs": {
"group": {
"terms": {
"field": "product.name"
},
"aggs": {
"group_docs": {
"top_hits": {
"size": 1,
"sort": [
{
"timestamp": {
"order": "desc"
}
}
]
}
}
}
}
}
}'
但是,我得到一个错误,说:
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "Fielddata is disabled on text fields by default. Set fielddata=true on [product.name] 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."
}
],
难道我绝对在这种情况下需要为此字段设置fielddata = true?如果不是,我该怎么办?如果是,我不知道如何设置它。我试图做这样说:
curl -XGET 'localhost:9200/xxx*/_search?pretty' -H 'Content-Type: application/json' -d'
{
"properties": {
"product.name": {
"type": "text",
"fielddata": true
}
},
"aggs": {
"group": {
"terms": {
"field": "product.name"
},
"aggs": {
"group_docs": {
"top_hits": {
"size": 1,
"sort": [
{
"timestamp": {
"order": "desc"
}
}
]
}
}
}
}
}
}'
不过,我觉得有什么不妥之处,我得到这个错误(synatactically?):
{
"error" : {
"root_cause" : [
{
"type" : "parsing_exception",
"reason" : "Unknown key for a START_OBJECT in [properties].",
"line" : 3,
"col" : 19
}
],
松懈,我刚刚逸岸在发布这个问题之后,我在上面的查询中把“field”:“product.name”替换为“field”:“product.name.keyword”,并且至少没有失败并且似乎返回正确的记录。我们是否真的需要使用上面的大部分,而不是用product.name.keywrod替换product.name?如果是,为什么?以及我如何在我上面的当前查询中包含这些内容? – user1892775
整个大部分都需要放在您的架构中。请张贴您的架构 – Lax