tra*_*nes 5 python elasticsearch-dsl
我想创建这个例子
GET /my_store/products/_search
{
"query" : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"term" : {
"price" : 20
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用Pythons 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")
Run Code Online (Sandbox Code Playgroud)
好的,这指定了主机,端口和索引.
s = s.filter("term", price = 20)
results = s.execute().to_dict()
Run Code Online (Sandbox Code Playgroud)
但是如何指定文档类型是"产品"?似乎在Search()函数中应该有一个参数.
类似的问题,假设我想运行相同的查询,但我希望它运行索引"my_store"和"her_store".我该如何指定?
你可以像这样使用.
s = Search(using=client, index=('my_report', 'my_store'), doc_type=('products'))
指数PARAM需要list,tuple,string类型.
在搜索构造函数中,您可以看到
if isinstance(index, (tuple, list)):
self._index = list(index)
elif index:
self._index = [index]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1852 次 |
| 最近记录: |