使用Python DSL在Elasticsearch中查询数组数据类型

7

整数数组数据类型的查询可以有多复杂?以下是我在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)

我正在将一个整数数组注入到捕获中。以下是有趣的一行代码:
paragraph.capture = [1, 0, 5, 7]
  1. 我可以查询一个数字是否在列表中: cnx = Search().using(client) s = cnx.query("match", capture=5)

  2. 正如 @Val 所说,我们可以添加另一个包含总和的字段来查询总和

如何查询特定的索引,例如 paragraph.capture[1] >= 1 ?

我们看到 Elasticsearch query on array index 与此相关,但我无法建立联系。

1个回答

1
最好的查询总和的方法是添加另一个包含总和的字段,这样您就不必在搜索时运行昂贵的脚本查询。
如果至少有一个数字大于4,则可以使用capture字段上的普通range查询来查询。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接