엘라스틱 서치는 데이터를 저장할때 실제로 검색에 사용되는 검색어인 Term으로 분석과정을 거쳐 저장하기 때문에 검색 시 대소문자, 단수 복수, 원형 여부와 상관없이 검색이 가능함. 이런 특징을 full text search, 한국어로는 전문검색이라고 함.
JPA의 QueryDSL과는 이름만 유사할 뿐임. 엘라스틱서치에서 검색을 위한 쿼리 기능을 QueryDSL이라고 함. 엘라스틱 서치의 QueryDSL은 모두 json형식으로 입력해야 함.
match_all
GET my_index/_search
match
GET my_index/_search
{
"query": {
"match": {
"message": "dog"
}
}
}
GET my_index/_search
{
"query": {
"match": {
"message": "quick dog"
}
}
}
GET my_index/_search
{
"query": {
"match": {
"message": {
"query": "quick dog",
"operator": "and"
}
}
}
}
match_phrase
GET my_index/_search
{
"query": {
"match_phrase": {
"message": "lazy dog"
}
}
}
GET my_index/_search
{
"query": {
"match_phrase": {
"message": {
"query": "lazy dog",
"slop": 1
}
}
}
}
query_string
url의 q파라미터를 이용해 검색 수행하는 방법을 json에도 적용하고 싶을때 사용
lazy나 jumping을 모두 포함하거나, quick dog구문을 포함하는 도큐먼트를 검색하는 쿼리
GET my_index/_search
{
"query": {
"query_string": {
"default_field": "message",
"query": "(jumping AND lazy) OR \\"quick dog\\""
}
}
}
여러 쿼리를 조합하기 위해서는 상위에 bool쿼리를 사용하고, 그 안에 다른 쿼리를 넣는 식으로 사용함. bool 쿼리는 다음의 4개의 인자를 갖고 있음.