This is my python code and wanted help pls help
#!/usr/bin/env python3
#-- coding: utf-8 --
import the Elasticsearch low-level client library
from elasticsearch import Elasticsearch
domain name, or server's IP address, goes in the 'hosts' list
elastic_client = Elasticsearch("http://localhost:9200/honraolocation")
User makes a request on client side
user_request = input("Pls type request ")
Take the user's parameters and put them into a Python
dictionary structured like an Elasticsearch query:
query_body = {
"query": {
"match": {
"title": user_requests
}
}
}
call the client's search() method, and have it return results
result = elastic_client.search(query = query_body)
see how many "hits" it returned using the len() function
print ("total hits:", len(result["hits"]["hits"]))
'''
MAKE ANOTHER CALL THAT RETURNS
MORE THAN 10 HITS BY USING THE 'size' PARAM
'''
result = elastic_client.search(query = query_body , size=999)
all_hits = result['hits']['hits']
see how many "hits" it returned using the len() function
print ("total hits using 'size' param:", len(result["hits"]["hits"]))
iterate the nested dictionaries inside the ["hits"]["hits"] list
for num, doc in enumerate(all_hits):
print ("DOC ID:", doc["_id"], "--->", doc, type(doc), "\n")
# Use 'iteritems()` instead of 'items()' if using Python 2
for key, value in doc.items():
print (key, "-->", value)
# print a few spaces between each doc for readability
print ("\n\n")