-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.py
49 lines (45 loc) · 1.55 KB
/
search.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
#! usr/bin/env python3
# -*- coding:utf-8 -*-
"""
@Author:zhoukaiyin
"""
from elasticsearch import Elasticsearch
es = Elasticsearch()
def search_elastic():
# _query = {
# 'query': {
# 'match': {
# "denotations": "Species",
# },
# }
# }
# _query = {
# 'query': {
# 'match_phrase': {
# 'denotations':{
# 'term':"mutation &",
# }
# }
# }
# }
_query = {
'query': {
'constant_score': {
'filter':{
'bool':{
'must':[
{"term":{"id":"29643855"}},
#{"term":{"denotations": "snp"}}
],
}
}
}
}
}
_searched = es.search(index='pubmed_index', doc_type='PubMed', body=_query)
for hit in _searched['hits']['hits']:
print(hit['_source'], flush=True)
print("Score:>>>>>>>", hit["_score"])
if __name__=="__main__":
search_elastic()
print(es.count(index='pubmed_index')['count'], 'documents in index')