代码之家  ›  专栏  ›  技术社区  ›  Noam

使用from和size的elasticsearch dsl

  •  0
  • Noam  · 技术社区  · 6 年前

    试图在查询中添加“from and limit”功能,以便在我的FE中进行分页,这会显示文档弹性返回,但“from”不起作用(即,我没有正确使用它,我的配偶)。

    s = Search(using=elastic_conn, index='my_index'). \
           filter("terms", organization_id=org_list)
    
        hits = s[my_from:my_size].execute() # if from = 10, size = 10 then I get 0 documents, altought 100 documents match the filters.
    

    我的索引包含100个文档。 如果我使用 my_from = 10 my_size = 10

    为什么?我是不是误用了from?

    文件说明:

    所以这看起来很简单,我遗漏了什么?

    0 回复  |  直到 6 年前
        1
  •  2
  •   Dalofeco    5 年前

    这个问题的答案可以在他们的文档中找到 Pagination Section of the Search DSL :

    分页

    要指定from/size参数,请使用Python切片API:

    s = s[10:20]
    
    # {"from": 10, "size": 10}
    

    这些参数在搜索DSL中的正确用法与在Python列表中一样,从开始索引到结束索引。size参数将隐式定义为结束索引减去开始索引。

    希望这能解决问题!