【问题标题】:Querying Array data type in elasticsearch using python_dsl使用python_dsl在elasticsearch中查询数组数据类型
【发布时间】:2017-09-04 12:41:24
【问题描述】:

对整数数组数据类型的查询有多复杂?这是我在 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所说,我们可以添加另一个包含sum的字段来查询总和

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

我们看到 Elasticsearch query on array index 是相关的,但我无法建立链接。

【问题讨论】:

    标签: python elasticsearch elasticsearch-dsl


    【解决方案1】:

    查询总和的最佳方法是添加另一个包含它的字段,这样您就不必在搜索时运行昂贵的script 查询。

    查询是否至少有一个数字大于 4 已经可以通过在 capture 字段上的普通 range 查询来完成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-12
      • 1970-01-01
      • 2013-01-28
      相关资源
      最近更新 更多