@@ -120,11 +120,12 @@ def _get_timestamp_filer(self):
120120 }
121121 }
122122
123- def _search (self , query , limit = 50000 , sampling = None ):
123+ def _search (self , query , fields = None , limit = 50000 , sampling = None ):
124124 """
125125 Perform the search and return raw rows
126126
127127 :type query object
128+ :type fields list[str] or None
128129 :type limit int
129130 :type sampling int or None
130131
@@ -142,6 +143,12 @@ def _search(self, query, limit=50000, sampling=None):
142143 }
143144 }
144145
146+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html
147+ if fields :
148+ body ['_source' ] = {
149+ "includes" : fields
150+ }
151+
145152 # add @timestamp range
146153 # @see http://stackoverflow.com/questions/40996266/elasticsearch-5-1-unknown-key-for-a-start-object-in-filters
147154 # @see https://discuss.elastic.co/t/elasticsearch-watcher-error-for-range-query/70347/2
@@ -184,11 +191,12 @@ def _search(self, query, limit=50000, sampling=None):
184191 self ._logger .info ("{:d} rows returned" .format (len (rows )))
185192 return rows
186193
187- def get_rows (self , match , limit = 10 , sampling = None ):
194+ def get_rows (self , match , fields = None , limit = 10 , sampling = None ):
188195 """
189196 Returns raw rows that matches given query
190197
191198 :arg match: query to be run against Kibana log messages (ex. {"@message": "Foo Bar DB queries"})
199+ :type fields list[str] or None
192200 :arg limit: the number of results (defaults to 10)
193201 :type sampling int or None
194202 :arg sampling: Percentage of results to be returned (0,100)
@@ -197,13 +205,14 @@ def get_rows(self, match, limit=10, sampling=None):
197205 "match" : match ,
198206 }
199207
200- return self ._search (query , limit , sampling )
208+ return self ._search (query , fields , limit , sampling )
201209
202- def query_by_string (self , query , limit = 10 , sampling = None ):
210+ def query_by_string (self , query , fields = None , limit = 10 , sampling = None ):
203211 """
204212 Returns raw rows that matches the given query string
205213
206214 :arg query: query string to be run against Kibana log messages (ex. @message:"^PHP Fatal").
215+ :type fields list[str] or None
207216 :arg limit: the number of results (defaults to 10)
208217 :type sampling int or None
209218 :arg sampling: Percentage of results to be returned (0,100)
@@ -214,7 +223,7 @@ def query_by_string(self, query, limit=10, sampling=None):
214223 }
215224 }
216225
217- return self ._search (query , limit , sampling )
226+ return self ._search (query , fields , limit , sampling )
218227
219228 def get_to_timestamp (self ):
220229 """ Return the upper time boundary to returned data """
0 commit comments