ELASTICSEARCH8 [엘라스틱서치] 8. Aggregations Aggregations : 집계 Metrics Aggregations : 산술 min, max, sum, Avg POST ball_index/_bulk { "index" : {"_id" : "1" } } {"team" : "Golden States Warriors","name" : "Stephen Curry", "points" : 30,"rebounds" : 3,"assists" : 4, "blocks" : 5, "submit_date" : "2024-10-11"} { "index" : {"_id" : "2" } } {"team" : "Golden States Warriors","name" : "Stephen Curry","points" : 20,"rebounds" : 5,"assists" : 8, "b.. 2024. 3. 14. [엘라스틱서치] 7. object, Geo 위치정보 Object movie로 조회하면 안 나옴. movie.name해야만 값이 조회가 됨 → name은 Loki이고, side는 villain인 문서를 검색 GET movies/_search { "query":{ "bool":{ "must":[ { "match":{ "movie.name":"Loki" } }, { "match":{ "movie.side":"villain" } } ] } } } name이 Loki인 것을 가지고 오고, 그 이후에 side가 villain인 것 가지고 온다. 결과 -> 2개의 문서를 가지고 온다. { "took": 15, "timed_out": false, "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 }.. 2024. 3. 14. [엘라스틱서치] 6. 한글 형태소, mapping 한글 형태소 설치 엘라스틱서치 -> bin위치에서 cmd창 열어서 설치하기 합성어(복합어) 처리 3가지 옵션 none : 복합어를 분리하지 않음 discard : 복합어 분리 mixed : none과 discard 모두 저장 PUT my_nori2 { "settings":{ "analysis":{ "tokenizer":{ "nori-none":{ "type":"nori_tokenizer", "discompound_mode":"none" }, "nori-discard":{ "type":"nori_tokenizer", "discompound_mode":"discard" }, "nori-mixed":{ "type":"nori_tokenizer", "discompound_mode":"mixed" } } } } .. 2024. 3. 13. [엘라스틱서치] 5. 데이터 색인, 사용자 정의 토큰 필터 데이터 색인 : 역인덱스 ( 단어 → 매핑문서 ) → tokenizer filter GET _analyze { "text":"Today is a day where I feel lucky and happy", "tokenizer":"whitespace", "filter":[ "lowercase", // 소문자로 변환 "stop", // 불용어 제외 "snowball" // 단어의 원형 ] } "snowball" // 단어의 원형 → 을 넣으면, y는 i 로 바뀌어서 저장됨 빼면 lucky, happy 그대로 나옴 "stop", // 불용어 제외 → is, a, and 이런거 빠짐, 빼고 넣으면 다 나옴 결과값 { "tokens": [ { "token": "today", "start_offset": 0, ".. 2024. 3. 13. [엘라스틱서치] 4. Bool query, Range query Bool query : 여러 쿼리를 조합하여 사용 가능 must : 쿼리가 참인 문서들을 검색 must_not : 쿼리가 거짓인 문서들을 검색 should : 검색 결과 중 이 쿼리에 해당하는 문서들의 score를 높여줌 filter : 쿼리가 참인 문서를 검색하지만, score를 계산하지 않음 must보다 검색 속도가 빠르다 [사용법] GET 인덱스명/_search { "query":{ "bool":{ "must":[ { 쿼리 }, ... ], "must_not":[ { 쿼리 }, ... ], "should":[ { 쿼리 }, ... ], "filter":[ { 쿼리 }, ... ] } } } EX01 ) 조건 - 팀이 jazz 이고, golden states 가 참인 것 ( 둘 다 참인 것 ) gol.. 2024. 3. 13. [엘라스틱서치] 3. 데이터 조건에 따라 검색하기 원하는 조건에 따라 검색이 가능하다. 먼저 이름이 park인 데이터를 조회하고, 이름이 park이면서 나이가 22인 데이터를 조회해본다. - term : 정확히 일치한 것 검색 ( 숫자 ) ⇒ 문자는 검색이 안될 수도 있다. ( 파싱한 값에 따라 달라지므로 잘 사용하지 않음 ) GET basketball/_search { "query" : { "term" : { "points":32 } } } - match : 단어가 포함되어 있으면 검색 ( 대/소문자 상관없음 ) GET basketball/_search { "query" : { "match" : { "team":"States" } } } + match에서 공백은 or를 의미한다. GET basketball/_search { "query" : { "ma.. 2024. 3. 11. 이전 1 2 다음