Created
August 20, 2022 02:56
-
-
Save seahrh/40ce2e6021d99338d6fac6f03b58346d to your computer and use it in GitHub Desktop.
ex. elasticsearch_dsl query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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