Skip to content

Instantly share code, notes, and snippets.

@seahrh
Created August 20, 2022 02:56
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 seahrh/40ce2e6021d99338d6fac6f03b58346d to your computer and use it in GitHub Desktop.
Save seahrh/40ce2e6021d99338d6fac6f03b58346d to your computer and use it in GitHub Desktop.
ex. elasticsearch_dsl query
import elasticsearch_dsl as es
hosts = ["http://1.1.1.1:9220","http://2.2.2.2:9220"]
es.connections.create_connection(hosts=hosts, http_auth=(username, password), timeout=300)
sea = es.Search(index=index_name).extra(from_=0, size=max_neighbors)
sea.query = es.Q(
'bool',
must=[
es.Q('match', field_1=text),
es.Q('term', field_2=f2),
],
)
# important! call execute to get scores. Do not use Scanner api.
hits = sea.execute()[:max_neighbors]
for i, hit in enumerate(hits):
print(f"i={i}, score={hit.meta.score}, {repr(hit.__dict__)}")
for k,v in hit.meta.__dict__.items():
print(f"\tmeta {k}={v}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment