-
gte (Greater-than or equal to) - 이상 (같거나 큼)
-
gt (Greater-than) – 초과 (큼)
-
lte (Less-than or equal to) - 이하 (같거나 작음)
-
lt (Less-than) - 미만 (작음)
POST phones/_bulk
{"index":{"_id":1}}
{"model":"Samsung GalaxyS 5","price":475,"date":"2014-02-24"}
{"index":{"_id":2}}
{"model":"Samsung GalaxyS 6","price":795,"date":"2015-03-15"}
{"index":{"_id":3}}
{"model":"Samsung GalaxyS 7","price":859,"date":"2016-02-21"}
{"index":{"_id":4}}
{"model":"Samsung GalaxyS 8","price":959,"date":"2017-03-29"}
{"index":{"_id":5}}
{"model":"Samsung GalaxyS 9","price":1059,"date":"2018-02-25"}
1. price 필드 값이 700 이상, 900 미만인 데이터를 검색
GET phones/_search
{
"query": {
"range": {
"price": {
"gte": 700,
"lt": 900
}
}
}
}
2. 2015년 12월 31일 부터 2018년 이전 사이에 있는 도큐먼트 검색
#dd/MM/yyyy으로 하면 에러남
GET phones/_search
{
"query": {
"range": {
"date": {
"gt": "31/12/2015",
"lt": "2018",
"format": "dd/MM/yyyy||yyyy"
}
}
}
}
3. 2016년 1월 1일에서 6개월 후인 날 부터 오늘보다 365일 전인 날 사이의 데이터를 가져오는 쿼리
#2016년 1월 1일에서 6개월 후인 날 부터 오늘보다 365일 전
GET phones/_search
{
"query": {
"range": {
"date": {
"gt": "2016-01-01||+6M",
"lt": "now-365d"
}
}
}
}
* range 쿼리는 기본적으로 정확도를 계산하지 않는다
기준값에서 가까운 Score를 찾는 방법은 아래 방법 참고
www.elastic.co/guide/en/elasticsearch/reference/7.3/query-dsl-function-score-query.html
Refernce : esbook.kimjmin.net/05-search/5.6-range