2017-09-04 88 views
6

查询对整数数组数据类型有多复杂?这是我在Python类以注入数据elasticsearch使用python_dsl查询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

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

查询至少有一个数字是否优于4可以使用capture字段上的正常range查询完成。