하나의 기사가 여러 게시물의 조합 인 기사 모음이 있습니다. 하나의 게시물은 ES에서 하나의 문서입니다. 모든 게시물에는 postId, articleId, 타임 스탬프 및 상태 (간체 버전)가 있습니다. 기사의 상태는 기록 된 동일한 기사 내의 마지막 소식의 상태입니다. 특정 상태의 기사를 쿼리하고 결과로 articleId 만 반환하려고합니다. 즉, articleId를 그룹화하고 timestamp별로 정렬 한 다음 최종 결과를 상태별로 필터링해야합니다.ElasticSearch : 응집시 필터링 top_hits
나는 그럭저럭 할 수 있었다. 그리고 나는 주문한다. 그러나 나는 마지막 일부 위에서 다소 붙이게된다.
우리의 데이터는 다음과 같이 좀 같습니다
postid articleId timestamp status
1 1 01.01.2016 00:00:01 Success
2 1 01.01.2016 00:00:03 Success
3 1 01.01.2016 00:00:02 Error
4 2 01.01.2016 00:00:01 Success
5 2 01.01.2016 00:00:03 Error
6 2 01.01.2016 00:00:02 Success
내 현재의 쿼리로 난이 얻을 :
articeid latestStatus
1 Success
2 Error
내가의은 articleID를 요청하는 쿼리를 작성하려면 (예를 들어) 상태가 '오류'인 모든 기사 내가 스크립팅 post_filter과 및 bucket_selector을 모두 사용하여 시도
GET /_search
{
"size": 0,
"aggs": {
"message_status": {
"terms": {
"field": "articleId"
},
"aggs": {
"group_docs": {
"top_hits": {
"size": 1,
"sort": [
{
"processed": {
"order": "desc"
}
}
]
}
}
}
}
}
}
하지만 동작하지 않습니다 :
articeid
2
이것은 내가 지금까지 무엇을 가지고 있습니다 : 이 쿼리는 반환해야합니다.
위의 질의는이 반환
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 6,
"max_score": 0,
"hits": []
},
"aggregations": {
"message_status": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "1337",
"doc_count": 3,
"group_docs": {
"hits": {
"total": 3,
"max_score": null,
"hits": [
{
"_index": "article",
"_type": "post",
"_id": "3",
"_score": null,
"_source": {
"postId": 3,
"articleId": "1337",
"processed": "2016-10-10T12:47:25.570852+02:00",
"statusId": 6
},
"sort": [
1476096445570
]
}
]
}
}
},
{
"key": "42",
"doc_count": 3,
"group_docs": {
"hits": {
"total": 3,
"max_score": null,
"hits": [
{
"_index": "article",
"_type": "post",
"_id": "6",
"_score": null,
"_source": {
"postId": 6,
"articleId": "42",
"processed": "2016-10-10T13:02:59.399726+02:00",
"statusId": 5
},
"sort": [
1476097379399
]
}
]
}
}
}
]
}
}
}
은 내가 지금 달성하고자하는 특정 statusId에이 응답을 필터링 만 articleIds을 반환하는 것입니다.
대단히 감사합니다!
가 업데이트 : 여기
는
{
"article": {
"mappings": {
"post": {
"properties": {
"articleId": {
"type": "string"
},
"postId": {
"type": "integer"
},
"processed": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"statusId": {
"type": "integer"
}
}
}
}
}
}
인덱스의 매핑을 공유하십시오. – Richa
솔루션이 작동 했습니까? – ChintanShah25