일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
- devtools
- framework
- typescript
- airflow
- json
- OPCUA
- query
- logstash
- kibana
- elastic
- 7.7.1
- Data Engineering
- ELK
- Tutorial
- KoA
- DSL
- package.json
- elasticsearch
- CSV
- ubuntu
- path.data
- configure
- grok
- node.js
- windows
- PYTHON
- dense_vector
- venv
- Crontab
- filebeat
- Today
- Total
목록elasticsearch (26)
Gibbs Kim's playground
opc-ua 서버를 테스트하던 도중 해당 데이터를 ES에 적재하여야 하는 상황을 겪었다. 이때, machinebeat라는 수집도구를 사용하여 opc-ua 서버에서 ES로 적재하는 것을 알게되었다. 해당 과정에 대한 수행내역을 기록해본다. 1) opc-ua 테스트용 서버 구축 https://mingsigi.tistory.com/entry/opc-ua-test-server-via-python opc ua test server via python from time import sleep import random from opcua import Server server = Server() server.set_endpoint("opc.tcp://127.0.0.1:12345") server.register_name..
Elastic Cloud에서 사전 적용을 하는 경우가 있어 관련 작업을 기록합니다. 사전 작성 (예시) stopwords.txt user_dictionary.txt synonyms.txt 해당 파일들은 dictionaries 폴더 아래에 저장이 되어 있어야 합니다. /dictionaries |---- stopwords.txt |---- user_dictionary.txt |---- synonyms.txt 파일을 Cloud에 적용하려면 다음과 같은 작업을 수행합니다. 1. dictionaries.zip 파일 생성 (위 폴더를 .zip파일화) 2. Elastic Cloud 접속 (cloud.elastic.co) 3. Deployment -> Features -> Extensions 접근 후 'Create e..
Elasticsearch는 Tokenizer를 통해 토큰이 모두 분리되면 다양한 토큰 필터를 적용할 수 있다.토큰 필터들 중 Synonym 필터를 적용한다면 동의어 처리에 대한 기능을 Elasticsearch를 통해 수행할 수 있다. * 동의어를 추가하는 방법1) 동의어를 mapping 설정 정보에 미리 파라미터로 등록하는 방식2) 특정 파일을 별도로 생성해서 관리하는 방식 (Ex: 동의어 사전) 첫 번째 방식은 실무에서 잘 사용되지 않는다. -> mapping 정보에서 동의어를 관리할 경우, 운영 중에는 동의어를 변경하기가 어렵기 때문 그래서 Elasticsearch에서 동의어는 주로 동의어 사전을 통해 관리된다. * 동의어 사전 만들기$ES_HOME/config/analysis/synonym.txt동..
Elasticsearch에서 모든 검색/집계의 기본 size는 10,000으로 설정되어 있다. 이중 집계는 bucket이라는 것을 사용하여 전체 문서를 대상으로 사용자의 기준(Ex : filter 등)에 따라 분류된 결과를 aggs 기능을 통해 표현한다. bucket의 size를 변경하려면 다음과 같은 방법들이 있다. PUT _cluster/settings { "transient": { "search.max_buckets": 20000 } } 해당 방식은 API를 활용하여 size를 조절하는 방식이다. # $ES_HOME/config/elasticsearch.yml "search.max_buckets": 20000 해당 방식은 Elasticsearch의 설정파일의 값을 조절하는 방식이다. 두 가지 방식 ..
Elasticsearch로 msearch를 수행할떄는 다음과 같은 패턴으로 작성을 하게 된다. GET _msearch {"index": "index1"} {"query": {"match_all": {}}} {"index": "index2"} {"query": {"match_all": {}}} {"index": "index3"} {"query": {"match_all": {}}} 참고 링크 만약 위와 같은 쿼리를 Elasticsearch-python module을 활용하여 수행하고 싶다면 다음과 같이 작성하자. from elasticsearch import Elasticsearch es = Elasticsearch() body = [ {"index": "index1"}, {"query": {"match_a..
리눅스에서 ES를 사용하다가 용량 문제 등으로 ES_HOME/data의 위치를 옮겨주어야 할 경우가 생긴다. 예를 들어 data 디렉토리를 /dev/data로 옮겼다고 하였을 때 ES에서 설정해주어야 할 것을 알아보자. 1) elasticsearch.yml "path.data": /dev/data 2) /dev/data 소유자 변경 sudo chown -R player:player /dev/data => 초기 복사된 /dev/data의 소유자는 root인 경우가 대부분이다. 이 때, elasticsearch의 소유자가 player라면 위와 같은 방법으로 설정하여 같은 소유자로 설정해주면 된다. (소유자가 root일 경우 access deny나 의도치않은 ps 충돌로 elasticsearch.bootstr..
엘라스틱서치는 벡터값들에 대한 내적 곱연산 (dotProduct)를 지원한다. 공식문서에서 제공하는 예제는 다음과 같다 (참고: https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-script-score-query.html#random-score-function) ### curl -X GET "localhost:9200/my_index/_search?pretty" -H 'Content-Type: application/json' -d' GET my_index/_search ### on Kibana DevTools { "query": { "script_score": { "query" : { "bool" : { "filter" : ..
일반적으로 Logstash에서 파일을 인덱싱하게 되면 ELK 7.0 이상 버전에서는 shard 가 1의 값을 디폴트로 가진다 (6.x 이하 버전은 shard 개수 5가 디폴트) 만약 어떤 인덱스가 ES에 적재된 후, shard 개수를 변경하려면 _reindex로 새 인덱스를 생성하는 것 말고는 답이 없다. 그래서 아예, 인덱싱 전에 템플릿을 작성하여 샤드를 조정할 수 있는 기능을 ES에서 제공한다. 다음을 보자. (참고 : https://www.elastic.co/guide/en/elasticsearch/reference/6.4/indices-templates.html) # curl -X PUT "localhost:9200/_template/template_1?pretty" -H 'Content-Type..
엘라스틱 서치를 실행하고 난 후, 접속 여부를 확인하기 위해 API 통신을 할 수 있다. 일반 적인 경우는 다음과 같다. curl -XGET localhost:9200 만약 추가로 X-Pack을 사용하여 유저를 생성하고 시큐리티 설정을 걸었다고 하자. (유저정보는 elastic/elastic123으로 가정) 그러면 API 명령을 다음과 같이 입력한다면 검색이 가능하다. curl --user elastic:elastic123 --insecure -XGET https://localhost:9200 무슨 차이냐 싶어서 확인해본 결과 --user 옵션으로 유저정보를 입력해주고 --insecure 옵션으로 https를 거쳐 접속을 가능하게 해주는듯 하다.
서로 다른 두 인덱스를 검색하는 쿼리가 다음과 같다고 하자. (참조: https://mingsigi.tistory.com/entry/ElasticStack-16-Terms-query-Aggregation-sum-avg) GET index_A/_search { "query": { "terms": { "subject": [ "국어", "영어", "수학" ] } }, "aggs": { "aggregation_naming_1": { "filter": { "term": { "file_name": "VALUE" } }, "aggs": { "aggregation_naming_2": { "sum": { "script": "doc.score.value" } } } } } } GET index_B/_search { "qu..