python
Import the Elasticsearch library
from elasticsearch import Elasticsearch
Connect to the Elasticsearch instance
es = Elasticsearch([{‘host’: ‘localhost’, ‘port’: 9200}])
Define a search query
query = {
“query”: {
“match”: {
“title”: “Python”
}
}
}
Execute the search query
results = es.search(index=”my_index”, body=query)
Print the search results
for hit in results[‘hits’][‘hits’]:
print(hit[‘_source’])

Leave a comment