2017-11-24 13 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 개의 다른 조각에서 결과를 얻었습니다.
그래서 결과 반드시이 보인다 : 당신이

쿼리 DSL의 크기를 설정할 수 있도록

{ 
    "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" 
     } 
     } 
    ] 
    } 
} 

hits에서 10 개 항목이 있으며, 그 때문에 결과 리턴의 기본 크기이며는 10이었다

GET /_search 
{ 
    "from" : 0, "size" : 10, 
    "query" : { 
     "term" : { "user" : "kimchy" } 
    } 
}