1. Elasticsearch Bool Query 사용하기
(1) must 조건 사용하기
GET nori_sample/_search
{
"track_total_hits": true,
"query": {
"bool": {
"must": [
{
"match": {
"document": "겨울"
}
}
]
}
}
}
(2) match_phrase_prefix 사용하기
GET nori_sample/_search
{
"track_total_hits": true,
"query": {
"bool": {
"must": [
{
"match_phrase_prefix": {
"document": "겨"
}
}
]
}
}
}
(3) should과 minumum_should_match 조건 사용하기
GET nori_sample/_search
{
"track_total_hits": true,
"query": {
"bool": {
"should": [
{
"match": {
"document": "여름"
}
},
{
"match" : {
"document" :"겨울"
}
}
],
"minimum_should_match" : 1
}
}
}
2. Aggregation 쓰기
(1) Visual Library 에서 Create를 하여 Lens와 데이터셋을 선택한다.
(2) bucket Aggregation을 확인한다.
Doc 하나를 여러개의 bucket으로 나누었고 bucket 별로 bar chart를 만든 모습이다.
(3) horizontal axis에서 Filters를 선택하여 filter을 쓸 수 있다.
(4) Significant Terms Aggregation 사용하기
New visualization에서 Aggregation based와 Tag cloud를 선택한다.
Bucket을 아래와 같이 설정한다.
위는 제조사 정보를 가지고 Aggregation을 한 모습이다.
Filter에서 여성복을 검색한다.
특정 카테고리를 잡았더니 중심이 되는 제조사가 바뀌었다. Significant Term Aggregation이 적용됐다. 빈도수 기반으로 분석 못하는 것들을 빠르게 확인할 수 있다.
(5) Metric Aggregation 사용하기
(6) Pipeline Aggregation 사용하기
(7) aggregation query로 사용하기
GET nori_sample/_search
{
"size" :0,
"query": {
"bool": {
"should": [
{
"match": {
"document": "여름"
}
},
{
"match": {
"document": "겨울"
}
}
],
"minimum_should_match": 1
}
},
"aggs":{
"result":{
"terms": {
"field": "label"
}
}
}
}
(8) Aggregation 여러 개 query로 사용하기
GET nori_sample/_search
{
"size" :0,
"query": {
"bool": {
"should": [
{
"match": {
"document": "여름"
}
},
{
"match": {
"document": "겨울"
}
}
],
"minimum_should_match": 1
}
},
"aggs":{
"result":{
"terms": {
"field": "label"
}
},
"r2":
{
"significant_terms": {
"field": "label"
}
}
}
}
Query → Bucket → Aggregation 순서로 진행된다.
'Cloud > ElasticSearch' 카테고리의 다른 글
[실습] Elasticsearch에서 Machine Learning 사용하기 (0) | 2023.12.29 |
---|---|
[개념] Elasticsearch에서의 Machine Learning (0) | 2023.12.29 |
[개념] Elasticsearch Query (Query DSL, Aggregation) (0) | 2023.12.29 |
[실습] Elasticsearch로 inverted index 추출하기, reindex 하기 (1) | 2023.12.29 |
[이론] Elasticsearch 형태소 분석기 (0) | 2023.12.29 |