g.l*_*lou 7 python elasticsearch elasticsearch-dsl
查询对整数数组数据类型有多复杂?这是我在python中的类,用于将数据注入elasticsearch:
class Paragraph(DocType):
body = Text(analyzer="standard")
published_from = Date()
lines = Integer()
n_paragraph = Integer()
capture = Integer()
class Meta:
index = "my_index"
def save(self, **kwargs):
self.lines = len(self.body.split())
return super(Paragraph, self).save(**kwargs)
Run Code Online (Sandbox Code Playgroud)
我在捕获中注入一个整数数组.这是有趣的路线:
paragraph.capture = [1, 0, 5, 7]
Run Code Online (Sandbox Code Playgroud)
我设法查询列表中是否有数字::
cnx = Search().using(client)
s = cnx.query("match", capture=5)
正如@Val所说,我们可以添加另一个包含sum的字段来查询总和
如何查询特定索引,例如paragraph.capture[1] >= 1?
我们看到Elasticsearch对数组索引的查询是相关的,但我无法建立链接.
查询总和的最佳方法是添加另一个包含该总和的字段,这样您就不必script在搜索时运行成本高昂的查询。
查询是否至少有一个数字大于 4 已经可以通过range对该capture字段进行普通查询来完成。