2014-07-21 33 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中,您只能設置索引。這可能是一個問題嗎?嘗試在不指定類型的情況下進行網絡查詢。