我想创建这个例子
GET /my_store/products/_search
{
"query" : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"term" : {
"price" : 20
}
}
}
}
}
使用 Python 的 elasticsearch_dsl。
import elasticsearch as ES
import elasticsearch_dsl as dsl
from elasticsearch_dsl import Search
client = ES.Elasticsearch() # i'm using the localhost default client
s = Search(using = client, index = "my_store")
好的,这指定了主机、端口和索引。
s = s.filter("term", price = 20)
results = s.execute().to_dict()
但是如何指定文档类型是“产品”?似乎 Search() 函数中应该有一个参数。
类似的问题,假设我想运行相同的查询,但我希望它在索引“my_store”和“her_store”上运行。我该如何指定?