I am trying to query from Jupyter a Elasticsearch index using Python. This is my code:
from elasticsearch import Elasticsearch
esHost="http://myhost.com:9600"
esUser="myuser"
esPass="mypass"
es = Elasticsearch(hosts=esHost, http_auth=(esUser, esPass))
query = {
"query": {
"bool": {
"must": {
"exists": {
"field": "pkey"
}
}
}
}
}
res = es.search(index="myindex", doc_type="articles", body=query)
res
The result I am getting is:
{'took': 1,
'timed_out': False,
'_shards': {'total': 6, 'successful': 6, 'skipped': 0, 'failed': 0},
'hits': {'total': 0, 'max_score': None, 'hits': []}}
However, when I run the same query in Kibana:
GET /myindex/_search?
{
"query": {
"bool": {
"must": {
"exists": {
"field": "pkey"
}
}
}
}
}
I am getting thousands of results:
{
"took" : 67,
"timed_out" : false,
"_shards" : {
"total" : 6,
"successful" : 6,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 12605121,
"max_score" : 1.0,
"hits" : [
{
...
What am I missing?
Just remove doc_type
in your python code, since this seems to be the only difference
res = es.search(index="myindex", doc_type="articles", body=query)
^
|
remove this parameter
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.