Skip to content

Instantly share code, notes, and snippets.

@drew2a
Last active March 22, 2023 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drew2a/e632fe807bb2462d6d33806ad194ae72 to your computer and use it in GitHub Desktop.
Save drew2a/e632fe807bb2462d6d33806ad194ae72 to your computer and use it in GitHub Desktop.
import sys
from elasticsearch import Elasticsearch
elastic_client = Elasticsearch('http://localhost:9200', request_timeout=120)
print('query:')
for line in sys.stdin:
query = {
"simple_query_string": {
"query": line.rstrip(),
}
}
result = elastic_client.search(index='tribler', query=query, size=50)
print(f'\nResults({result.body["took"] / 1000}s):')
printed_infohashes = set()
for hit in result.body['hits']['hits']:
infohash = hit['_source']['infohash']
if infohash in printed_infohashes:
continue
print(f"{hit['_source']['title']} [score: {hit['_score']} infohash: {infohash}]")
printed_infohashes.add(infohash)
print('\nquery:')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment