-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseacher.py
28 lines (24 loc) · 856 Bytes
/
seacher.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
import re
from elasticsearch import Elasticsearch
from elasticsearch_dsl import *
from elasticsearch_dsl.connections import connections
if __name__ == "__main__":
# make predictive.(i.e can handle common errors)
key = raw_input('Enter the search query: ')
lst_urls = []
## establish the connection between elasticSearch and python
es = Elasticsearch(['http://localhost:9200/'],verify_certs=True)
#es = connections.create_connection(hosts=['re-es.canary'])
es.indices.refresh(index="engine")
search_body = {
"query":{
"match":{
"pageData":key
}
}
}
res = es.search(index="engine",body=search_body)
for hit in res['hits']['hits']:
data = hit["_source"]
lst_urls.append(data["url"])
print(lst_urls)