2014-07-21 18 views
0

我使用ES的python API来发送请求,我尝试获取我的答案的结果,但它是错误的。 我用这个代码:Elasticsearch和Python:获取总变量

import elasticsearch 

    es = elasticsearch.Elasticsearch(["127.0.0.1:9200"]) 
    results = es.search(index="bhinneka", body={"query": {"match": {"name": '"'+reference+'"'}}}) 

    if results['hits']: 
     print('-' * 80) 
     print results['hits']['total'] 

    for hit in results['hits']['hits']: 
     print hit['_source']['name'] 

事实上,当我从我的网页浏览器验证的结果,我已经得到了 - 因为在5例 - 总变,我的代码我已经得到了在总42例如 - 。

如果有人回答这个谜,我很感兴趣:)

在此先感谢

+0

如何验证Web浏览器的结果?也许你使用一个插件,一次返回5个结果? – Ashalynd

回答

0

我使用此查询:

127.0.0.1:9200/bhinneka/bhinneka/_search?q=name:%22reference%22&pretty=true 

而且我已经得到了这样的结果:

{ 
    ... 
    "hits": { 
    "total": 5, 
    "max_score": 9.990799, 
    "hits": [ 
     { 
     "_index": "bhinneka", 
     "_type": "bhinneka", 
     "_id": "ySosUTHKSESxo7ScOOhUZw", 
     "_score": 9.990799, 
     "_source": { 
      ... 
     } 
     } 
    ] 
    } 
} 
0

在您的网页查询中,您指定了类型和索引bhinneka,而在Python中,您只能设置索引。这可能是一个问题吗?尝试在不指定类型的情况下进行网络查询。