Elastic/elasticsearch
[es] script query
father6019
2023. 8. 31. 22:57
728x90
반응형
불용어 (stopword) 필터를 사용해 analyzer 에서 불용어를 걸러낼 수는 있지만..
이 no result 케이스에서 불용어때문에 걸러진건지 실제 true 인 데이터가 없는건지 알아내야 한다..
왜냐..면
이 케이스에서 확장검색이 들어가야 하는데 이 확장검색이란 놈이 operator 가 or 이기때문에 조합형 불용어 에서는
정밀도가 떨어지는 검색결과가 나오게 되어 이 케이스를 없애달라는.. 원하는건 불용어를 포함한 검색어 일때
no result 처리
주의할점! 은 스크립트를 사용하면 검색속도가 느려질 수 있다.
암튼.. 일단 만들어 보자
es 는 8.8.1 버전에서 키바나와 es 만 실행
#내 로컬 경로
cd /Users/doo/docker/es8.8.1
실행
#-f 옵션으로 파일지정
#-d 백그라운드 실행
#--build 빌드
docker compose -f docker-compose-es-kibana.yml up -d --build
kibana 접속
http://localhost:5601/app/dev_tools#/console
#license 삭제
DELETE _license
인덱스 생성
PUT /stopwords
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"properties": {
"keyword": {
"type": "text",
"fielddata": true
}
}
}
}
불용어 색인
- 18놈
- 개새끼
- g랄
- 좆까
POST _bulk
{"index":{"_index":"stopwords", "_id":"1"}}
{"keyword":"18놈"}
{"index":{"_index":"stopwords", "_id":"2"}}
{"keyword":"개새끼"}
{"index":{"_index":"stopwords", "_id":"3"}}
{"keyword":"g랄"}
{"index":{"_index":"stopwords", "_id":"4"}}
{"keyword":"좆까"}
contains 사용하여 비교
GET stopwords/_search
{
"query": {
"bool": {
"filter": {
"script": {
"script": {
"source": "params.input.toLowerCase().contains(doc['keyword'].value)",
"lang": "painless",
"params": {
"input": "18놈아 죽고싶니"
}
}
}
}
}
}
}
실행결과
불용어 '18놈' 을 포함한 키워드 '18놈아 죽고싶니' 가 입력 되어었을때 검색결과
해당케이스에서 확장검색 실행 안함
728x90
반응형