2017-11-24 1 views
0

elasticsearch python APIを使用してELKセットアップに対して検索を実行しようとしています。デフォルトでは、検索はインデックスから5つの結果しか返しません。インデックスから利用可能なすべての断片を返すように設定するにはどうすればよいですか? kibannaダッシュボードには、900個の+破片を示しているが、APIは、現時点では5私のコードを返している:スクリプト・ショー(上部)からElasticsearch Python APIを使用する際に、どのようにすべてのシャードを返すことができますか?

es = Elasticsearch([{'host': 'localhost', 'port': 9200}]) 

data = es.search(
    index='scapy' 
) 

出力:から

{u'_shards': {u'failed': 0, u'skipped': 0, u'successful': 5, u'total': 5}, 

スクリーンショットkibannaダッシュボード:

enter image description here

ありがとう!

答えて

0

オプションパラメータのサイズはより多くのあなたがミスを犯したしなければならない

count = es.count(index='scapy')['count'] 
data = es.search(index='scapy', size=count) 
0

を結果表示するように設定することができますが、結果を理解し、 結果

{u'_shards': {u'failed': 0, u'skipped': 0, u'successful': 5, u'total': 5} 

はインデックス「scapyのそれはあなたのデータの意味します'は5種類の断片に分かれていて、あなたの検索クエリはこれらの5種類の断片から結果を得ました。
だから結果はこのように思えるする必要があります。

{ 
    "took": 1651, 
    "timed_out": false, 
    "_shards": { 
    "total": 10, 
    "successful": 10, 
    "skipped": 0, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 2221327255, 
    "max_score": 1, 
    "hits": [ 
     { 
     "_index": "test_index", 
     "_type": "logs", 
     "_id": "BL1E-F8BH3R02gVcxkPc", 
     "_score": 1, 
     "_source": { 
      "deviceType": "4", 
      "appVersion": "2.1.1" 
     } 
     }, 
     { 
     "_index": "test_index", 
     "_type": "logs", 
     "_id": "Cr1E-F8BH3R02gVcxkPd", 
     "_score": 1, 
     "_source": { 
      "deviceType": "4", 
      "appVersion": "2.1.1" 
     } 
     }, 
     { 
     "_index": "test_index", 
     "_type": "logs", 
     "_id": "Eb1E-F8BH3R02gVcxkPd", 
     "_score": 1, 
     "_source": { 
      "deviceType": "4", 
      "appVersion": "2.1.2" 
     } 
     }, 
     { 
     "_index": "test_index", 
     "_type": "logs", 
     "_id": "F71E-F8BH3R02gVcxkPd", 
     "_score": 1, 
     "_source": { 
      "deviceType": "4", 
      "appVersion": "2.1.2" 
     } 
     }, 
     { 
     "_index": "test_index", 
     "_type": "logs", 
     "_id": "KL1E-F8BH3R02gVcxkPd", 
     "_score": 1, 
     "_source": { 
      "deviceType": "4", 
      "appVersion": "2.1.2" 
     } 
     }, 
     { 
     "_index": "test_index", 
     "_type": "logs", 
     "_id": "LL1E-F8BH3R02gVcxkPd", 
     "_score": 1, 
     "_source": { 
      "deviceType": "4", 
      "appVersion": "2.1.2" 
     } 
     }, 
     { 
     "_index": "test_index", 
     "_type": "logs", 
     "_id": "NL1E-F8BH3R02gVcxkPd", 
     "_score": 1, 
     "_source": { 
      "deviceType": "4", 
      "appVersion": "2.1.2" 
     } 
     }, 
     { 
     "_index": "test_index", 
     "_type": "logs", 
     "_id": "R71E-F8BH3R02gVcxkPd", 
     "_score": 1, 
     "_source": { 
      "deviceType": "4", 
      "appVersion": "2.1.2" 
     } 
     }, 
     { 
     "_index": "test_index", 
     "_type": "logs", 
     "_id": "Sb1E-F8BH3R02gVcxkPd", 
     "_score": 1, 
     "_source": { 
      "deviceType": "4", 
      "appVersion": "2.1.2" 
     } 
     }, 
     { 
     "_index": "test_index", 
     "_type": "logs", 
     "_id": "TL1E-F8BH3R02gVcxkPd", 
     "_score": 1, 
     "_source": { 
      "deviceType": "4", 
      "appVersion": "2.1.2" 
     } 
     } 
    ] 
    } 
} 

10の項目がhitsであり、それが原因で、結果の戻りのデフォルトのサイズである10だったので、あなたは、あなたの質問DSLで

をサイズを設定することができます
GET /_search 
{ 
    "from" : 0, "size" : 10, 
    "query" : { 
     "term" : { "user" : "kimchy" } 
    } 
} 
関連する問題