elasticsearch,pyes,Python,elasticsearch,Pyes" /> elasticsearch,pyes,Python,elasticsearch,Pyes" />

Python 使用pyes使用exists构建ElasticSearch搜索

Python 使用pyes使用exists构建ElasticSearch搜索,python,elasticsearch,pyes,Python,elasticsearch,Pyes,此示例代码的目标是了解如何创建由多个过滤器和查询组成的查询 下面的示例未按预期工作 我想能够执行我的搜索只对文件,其中包含一个特定的“键”。这就是我试图通过ExistsFilter实现的目标,但是启用时我没有得到任何结果 有什么可以澄清这个问题的建议吗 #!/usr/bin/python import pyes conn = pyes.ES('sandbox:9200') conn.index('{"test":{"field1":"value1","field2":"value2"}}','

此示例代码的目标是了解如何创建由多个过滤器和查询组成的查询

下面的示例未按预期工作

  • 我想能够执行我的搜索只对文件,其中包含一个特定的“键”。这就是我试图通过ExistsFilter实现的目标,但是启用时我没有得到任何结果
  • 有什么可以澄清这个问题的建议吗

    #!/usr/bin/python
    
    import pyes
    conn = pyes.ES('sandbox:9200')
    conn.index('{"test":{"field1":"value1","field2":"value2"}}','2012.9.23','test')
    
    filter = pyes.filters.BoolFilter()
    filter.add_must(pyes.filters.LimitFilter(1))
    filter.add_must(pyes.filters.ExistsFilter('test')) #uncommenting this line returns the documents
    
    query = pyes.query.BoolQuery()
    query.add_must(pyes.query.TextQuery('test.field1','value1'))
    query.add_must(pyes.query.TextQuery('test.field2','value2'))
    
    search = pyes.query.FilteredQuery(query, filter)
    
    for reference in conn.search(query=search,indices=['2012.9.23']):
        print reference
    
    我不使用pyes(也不使用python)。但是,我在这里看到的是,与文档相比,ExistsFilter中似乎遗漏了一些信息:

    {
        "constant_score" : {
            "filter" : {
                "exists" : { "field" : "user" }
            }
        }
    }
    
    这可能是你的问题吗