我正在使用pyes Python库进行elasticsearch。
假设我想找到title =“Rainbow”AND artist =“Kermit”的所有文件。以下文件返回title =“Rainbow”OR artist =“Kermit”的文档。如何将其更改为AND?
query = pyes.TermQuery()
query.add("title", "rainbow")
query.add("artist","kermit")
search = pyes.Search(query)
results = conn.search(search, index_name, doc_type)
答案 0 :(得分:3)
答案是将两个TermQuery包装在BooleanQuery
中q1 = pyes.TermQuery("title", "rainbow")
q2 = pyes.TermQuery("artist", "kermit")
query = BooleanQuery(must=[q1, q2])
search = pyes.Search(query)
results = conn.search(search, index_name, doc_type)