-
Notifications
You must be signed in to change notification settings - Fork 8
/
elastic_test.py
59 lines (53 loc) · 1.25 KB
/
elastic_test.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
from subprocess import Popen, PIPE, STDOUT
from elasticsearch import Elasticsearch
import json
import pandas as pd
from tqdm import tqdm
import time
import re
# 172.17.0.2
es_server = Popen(
["../elasticsearch-7.15.1/bin/elasticsearch"],
stdout=PIPE,
stderr=STDOUT,
preexec_fn=lambda: os.setuid(1),
)
INDEX_NAME = "document"
INDEX_SETTINGS = {
"settings": {
"index": {
"analysis": {
"analyzer": {
"korean": {
"type": "custom",
"tokenizer": "nori_tokenizer",
"filter": ["shingle"],
}
}
}
}
},
"mappings": {
"properties": {
"content": {
"type": "text",
"analyzer": "korean",
"search_analyzer": "korean",
},
"title": {
"type": "text",
"analyzer": "korean",
"search_analyzer": "korean",
},
}
},
}
try:
es.transport.close()
except:
pass
es = Elasticsearch()
if es.indices.exists(INDEX_NAME, request_timeout=10):
es.indices.delete(index=INDEX_NAME, request_timeout=10)
print(es.info())