2017-09-04 87 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查詢完成。