Skip to main content

Elasticsearch


Query DSL

match_all

GET /<index>/_search
{
"query": {
"match_all": {}
}
}

match

GET /<index>/_search
{
"query": {
"match": {
"<field>": {
"query": "<value>",
"operator": "and"
}
}
}
}

기본적으로 단어 사이의 띄어쓰기는 "operator": "or"로 처리됩니다.

range

GET /<index>/_search
{
"query": {
"range": {
"<field>": {
"gte": "<value>",
"lte": "<value>"
}
}
}
}

bool

GET /<index>/_search
{
"query": {
"bool": {
"filter": [
{
"match": {
"<field>": {
"query": "<value>",
"operator": "and"
}
}
}
]
}
}
}

Aggregations

POST /<index>/_search
{
"query": { // 검색 조건을 추가하여 범위를 줄일 수 있습니다.
// ...
},
"size": 0, // 검색 결과는 반환하지 않고, 집계 결과만 반환합니다.
"aggs": {
"<aggregation_name>": {
"<aggregation_type>": {
"<aggregation_option>": "<aggregation_option_value>"
}
},
}
}

Date histogram

POST /<index>/_search
{
"aggs": {
"<aggregation_name>": {
"date_histogram": {
"field": "<date_field>",
"calendar_interval": "1d"
}
}
}
}

Pipeline

아래와 같이 날짜 기준으로 집계한 결과를 다시 집계할 수 있습니다.

POST /<index>/_search
{
"aggs": {
"<aggregation_name>": {
"date_histogram": {
"field": "<date_field>",
"calendar_interval": "day"
},
"aggs": {
"<aggregation_name>": {
"<aggregation_type>": {
"<aggregation_option>": "<aggregation_option_value>"
}
}
}
}
}
}