'Elasticsearch query multiple terms from a list
I want to retrieve the documents that must contain the terms from the given list in the body of the document and may or may not contain the seq items. I have nearly 2000 seq items, but for example I have used only 3 seq items. How do I pass these terms to the query using python?
from elasticsearch_dsl import Search
from elasticsearch_dsl.query import Q
terms = ['collagen', 'reticular', 'anti ageing peptide']
seq = ['MEVGWYRSPFSRVVHLYRNGK','AGVFDIDLDQPEDAGSEDEL','AKKVFKRLEKLFSKIQNDK']
q = Q('bool', must = [Q('match_phrase', body = terms)],
should = [Q('match_phrase', body = seq)])
search = Search(using=es, index='pmc_article').query(q)
results = search.execute()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
