scala에서 elatic4s에서 복합 쿼리(compound query)를 실행하는 예제이다.
should 다음에 바로 뒤에 query를 사용하면 문제가 생긴다.
쿼리가 하나 손실되는 예제
shoud {
matchQuery
rangeQuery
}
appendShould 예제를 잘 사용하는 것을 추천한다.
search(searchData.serviceTag / DEFAULT_TYPE).
query {
bool {
must {
matchQuery("message", searchData.grep)
} appendMust {
rangeQuery("@timestamp").gte(searchData.startDateTime).lte(searchData.endDateTime)
}
}
}.size(searchData.size).sortByFieldDesc("@timestamp")
요청 json은 다음과 같다.
{
"query":{
"bool":{
"should":[
{
"match":{
"message":{
"query":"*HTTP*"
}
}
},
{
"range":{
"@timestamp":{
"gte":"2017-11-14T14:00:00+09:00",
"lte":"2017-11-14T15:00:00+09:00"
}
}
}
]
}
},
"size":10,
"sort":[
{
"@timestamp":{
"order":"desc"
}
}
]
}
이 두개의 짝을 잘 맞춰 개발할 필요가 있다.
should->appendShould
must->mustShould
'scala' 카테고리의 다른 글
[scala]play2.6에 webjars 연동하기 (0) | 2017.11.27 |
---|---|
[play2] template 예시 (0) | 2017.11.23 |
[scala] elastic4s의 json 쿼리 요청 보기 (0) | 2017.11.21 |
[scala] connection pool과 with 메소드로 간결하게 코딩하기 (0) | 2017.11.21 |
scala에서의 jodatime(ISO8601) 예제 (0) | 2017.11.20 |