python 实现上面的查询语句:
# -*- coding:utf-8 -*-
from elasticsearch import Elasticsearch
import json
es = Elasticsearch()
dsl = {"query":{"bool":{"must":[],"must_not":[],"should":[{"query_string":{"default_field":"_all","query":"渔船"}}]}},"from":0,"size":10,"sort":[],"aggs":{}}
result = es.search(index='news2', doc_type='politics', body=dsl)
print(json.dumps(result, indent=1, ensure_ascii=False))
查询结果:
{
"_shards": {
"successful": 5,
"total": 5,
"failed": 0
},
"took": 3,
"timed_out": false,
"hits": {
"total": 1,
"hits": [
{
"_type": "politics",
"_score": 0.08184852,
"_source": {
"url": "https://news.qq.com/a/20111216/001044.htm",
"title": "中韩渔警冲突调查:韩警平均每天扣1艘中国渔船",
"date": "2011-12-17"
},
"_index": "news2",
"_id": "AWcayRM2HuPv2Z-oKjDg"
}
],
"max_score": 0.08184852
}
}
Process finished with exit code 0