delete_by_query.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. // Copyright 2012-present Oliver Eilhard. All rights reserved.
  2. // Use of this source code is governed by a MIT-license.
  3. // See http://olivere.mit-license.org/license.txt for details.
  4. package elastic
  5. import (
  6. "context"
  7. "fmt"
  8. "net/url"
  9. "strings"
  10. "gopkg.in/olivere/elastic.v5/uritemplates"
  11. )
  12. // DeleteByQueryService deletes documents that match a query.
  13. // See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-delete-by-query.html.
  14. type DeleteByQueryService struct {
  15. client *Client
  16. index []string
  17. typ []string
  18. query Query
  19. body interface{}
  20. xSource []string
  21. xSourceExclude []string
  22. xSourceInclude []string
  23. analyzer string
  24. analyzeWildcard *bool
  25. allowNoIndices *bool
  26. conflicts string
  27. defaultOperator string
  28. df string
  29. docvalueFields []string
  30. expandWildcards string
  31. explain *bool
  32. from *int
  33. ignoreUnavailable *bool
  34. lenient *bool
  35. lowercaseExpandedTerms *bool
  36. preference string
  37. q string
  38. refresh string
  39. requestCache *bool
  40. requestsPerSecond *int
  41. routing []string
  42. scroll string
  43. scrollSize *int
  44. searchTimeout string
  45. searchType string
  46. size *int
  47. sort []string
  48. stats []string
  49. storedFields []string
  50. suggestField string
  51. suggestMode string
  52. suggestSize *int
  53. suggestText string
  54. terminateAfter *int
  55. timeout string
  56. trackScores *bool
  57. version *bool
  58. waitForActiveShards string
  59. waitForCompletion *bool
  60. pretty bool
  61. }
  62. // NewDeleteByQueryService creates a new DeleteByQueryService.
  63. // You typically use the client's DeleteByQuery to get a reference to
  64. // the service.
  65. func NewDeleteByQueryService(client *Client) *DeleteByQueryService {
  66. builder := &DeleteByQueryService{
  67. client: client,
  68. }
  69. return builder
  70. }
  71. // Index sets the indices on which to perform the delete operation.
  72. func (s *DeleteByQueryService) Index(index ...string) *DeleteByQueryService {
  73. s.index = append(s.index, index...)
  74. return s
  75. }
  76. // Type limits the delete operation to the given types.
  77. func (s *DeleteByQueryService) Type(typ ...string) *DeleteByQueryService {
  78. s.typ = append(s.typ, typ...)
  79. return s
  80. }
  81. // XSource is true or false to return the _source field or not,
  82. // or a list of fields to return.
  83. func (s *DeleteByQueryService) XSource(xSource ...string) *DeleteByQueryService {
  84. s.xSource = append(s.xSource, xSource...)
  85. return s
  86. }
  87. // XSourceExclude represents a list of fields to exclude from the returned _source field.
  88. func (s *DeleteByQueryService) XSourceExclude(xSourceExclude ...string) *DeleteByQueryService {
  89. s.xSourceExclude = append(s.xSourceExclude, xSourceExclude...)
  90. return s
  91. }
  92. // XSourceInclude represents a list of fields to extract and return from the _source field.
  93. func (s *DeleteByQueryService) XSourceInclude(xSourceInclude ...string) *DeleteByQueryService {
  94. s.xSourceInclude = append(s.xSourceInclude, xSourceInclude...)
  95. return s
  96. }
  97. // Analyzer to use for the query string.
  98. func (s *DeleteByQueryService) Analyzer(analyzer string) *DeleteByQueryService {
  99. s.analyzer = analyzer
  100. return s
  101. }
  102. // AnalyzeWildcard specifies whether wildcard and prefix queries should be
  103. // analyzed (default: false).
  104. func (s *DeleteByQueryService) AnalyzeWildcard(analyzeWildcard bool) *DeleteByQueryService {
  105. s.analyzeWildcard = &analyzeWildcard
  106. return s
  107. }
  108. // AllowNoIndices indicates whether to ignore if a wildcard indices
  109. // expression resolves into no concrete indices (including the _all string
  110. // or when no indices have been specified).
  111. func (s *DeleteByQueryService) AllowNoIndices(allow bool) *DeleteByQueryService {
  112. s.allowNoIndices = &allow
  113. return s
  114. }
  115. // Conflicts indicates what to do when the process detects version conflicts.
  116. // Possible values are "proceed" and "abort".
  117. func (s *DeleteByQueryService) Conflicts(conflicts string) *DeleteByQueryService {
  118. s.conflicts = conflicts
  119. return s
  120. }
  121. // AbortOnVersionConflict aborts the request on version conflicts.
  122. // It is an alias to setting Conflicts("abort").
  123. func (s *DeleteByQueryService) AbortOnVersionConflict() *DeleteByQueryService {
  124. s.conflicts = "abort"
  125. return s
  126. }
  127. // ProceedOnVersionConflict aborts the request on version conflicts.
  128. // It is an alias to setting Conflicts("proceed").
  129. func (s *DeleteByQueryService) ProceedOnVersionConflict() *DeleteByQueryService {
  130. s.conflicts = "proceed"
  131. return s
  132. }
  133. // DefaultOperator for query string query (AND or OR).
  134. func (s *DeleteByQueryService) DefaultOperator(defaultOperator string) *DeleteByQueryService {
  135. s.defaultOperator = defaultOperator
  136. return s
  137. }
  138. // DF is the field to use as default where no field prefix is given in the query string.
  139. func (s *DeleteByQueryService) DF(defaultField string) *DeleteByQueryService {
  140. s.df = defaultField
  141. return s
  142. }
  143. // DefaultField is the field to use as default where no field prefix is given in the query string.
  144. // It is an alias to the DF func.
  145. func (s *DeleteByQueryService) DefaultField(defaultField string) *DeleteByQueryService {
  146. s.df = defaultField
  147. return s
  148. }
  149. // DocvalueFields specifies the list of fields to return as the docvalue representation of a field for each hit.
  150. func (s *DeleteByQueryService) DocvalueFields(docvalueFields ...string) *DeleteByQueryService {
  151. s.docvalueFields = docvalueFields
  152. return s
  153. }
  154. // ExpandWildcards indicates whether to expand wildcard expression to
  155. // concrete indices that are open, closed or both. It can be "open" or "closed".
  156. func (s *DeleteByQueryService) ExpandWildcards(expand string) *DeleteByQueryService {
  157. s.expandWildcards = expand
  158. return s
  159. }
  160. // Explain specifies whether to return detailed information about score
  161. // computation as part of a hit.
  162. func (s *DeleteByQueryService) Explain(explain bool) *DeleteByQueryService {
  163. s.explain = &explain
  164. return s
  165. }
  166. // From is the starting offset (default: 0).
  167. func (s *DeleteByQueryService) From(from int) *DeleteByQueryService {
  168. s.from = &from
  169. return s
  170. }
  171. // IgnoreUnavailable indicates whether specified concrete indices should be
  172. // ignored when unavailable (missing or closed).
  173. func (s *DeleteByQueryService) IgnoreUnavailable(ignore bool) *DeleteByQueryService {
  174. s.ignoreUnavailable = &ignore
  175. return s
  176. }
  177. // Lenient specifies whether format-based query failures
  178. // (such as providing text to a numeric field) should be ignored.
  179. func (s *DeleteByQueryService) Lenient(lenient bool) *DeleteByQueryService {
  180. s.lenient = &lenient
  181. return s
  182. }
  183. // LowercaseExpandedTerms specifies whether query terms should be lowercased.
  184. func (s *DeleteByQueryService) LowercaseExpandedTerms(lowercaseExpandedTerms bool) *DeleteByQueryService {
  185. s.lowercaseExpandedTerms = &lowercaseExpandedTerms
  186. return s
  187. }
  188. // Preference specifies the node or shard the operation should be performed on
  189. // (default: random).
  190. func (s *DeleteByQueryService) Preference(preference string) *DeleteByQueryService {
  191. s.preference = preference
  192. return s
  193. }
  194. // Q specifies the query in Lucene query string syntax. You can also use
  195. // Query to programmatically specify the query.
  196. func (s *DeleteByQueryService) Q(query string) *DeleteByQueryService {
  197. s.q = query
  198. return s
  199. }
  200. // QueryString is an alias to Q. Notice that you can also use Query to
  201. // programmatically set the query.
  202. func (s *DeleteByQueryService) QueryString(query string) *DeleteByQueryService {
  203. s.q = query
  204. return s
  205. }
  206. // Query sets the query programmatically.
  207. func (s *DeleteByQueryService) Query(query Query) *DeleteByQueryService {
  208. s.query = query
  209. return s
  210. }
  211. // Refresh indicates whether the effected indexes should be refreshed.
  212. func (s *DeleteByQueryService) Refresh(refresh string) *DeleteByQueryService {
  213. s.refresh = refresh
  214. return s
  215. }
  216. // RequestCache specifies if request cache should be used for this request
  217. // or not, defaults to index level setting.
  218. func (s *DeleteByQueryService) RequestCache(requestCache bool) *DeleteByQueryService {
  219. s.requestCache = &requestCache
  220. return s
  221. }
  222. // RequestsPerSecond sets the throttle on this request in sub-requests per second.
  223. // -1 means set no throttle as does "unlimited" which is the only non-float this accepts.
  224. func (s *DeleteByQueryService) RequestsPerSecond(requestsPerSecond int) *DeleteByQueryService {
  225. s.requestsPerSecond = &requestsPerSecond
  226. return s
  227. }
  228. // Routing is a list of specific routing values.
  229. func (s *DeleteByQueryService) Routing(routing ...string) *DeleteByQueryService {
  230. s.routing = append(s.routing, routing...)
  231. return s
  232. }
  233. // Scroll specifies how long a consistent view of the index should be maintained
  234. // for scrolled search.
  235. func (s *DeleteByQueryService) Scroll(scroll string) *DeleteByQueryService {
  236. s.scroll = scroll
  237. return s
  238. }
  239. // ScrollSize is the size on the scroll request powering the update_by_query.
  240. func (s *DeleteByQueryService) ScrollSize(scrollSize int) *DeleteByQueryService {
  241. s.scrollSize = &scrollSize
  242. return s
  243. }
  244. // SearchTimeout defines an explicit timeout for each search request.
  245. // Defaults to no timeout.
  246. func (s *DeleteByQueryService) SearchTimeout(searchTimeout string) *DeleteByQueryService {
  247. s.searchTimeout = searchTimeout
  248. return s
  249. }
  250. // SearchType is the search operation type. Possible values are
  251. // "query_then_fetch" and "dfs_query_then_fetch".
  252. func (s *DeleteByQueryService) SearchType(searchType string) *DeleteByQueryService {
  253. s.searchType = searchType
  254. return s
  255. }
  256. // Size represents the number of hits to return (default: 10).
  257. func (s *DeleteByQueryService) Size(size int) *DeleteByQueryService {
  258. s.size = &size
  259. return s
  260. }
  261. // Sort is a list of <field>:<direction> pairs.
  262. func (s *DeleteByQueryService) Sort(sort ...string) *DeleteByQueryService {
  263. s.sort = append(s.sort, sort...)
  264. return s
  265. }
  266. // SortByField adds a sort order.
  267. func (s *DeleteByQueryService) SortByField(field string, ascending bool) *DeleteByQueryService {
  268. if ascending {
  269. s.sort = append(s.sort, fmt.Sprintf("%s:asc", field))
  270. } else {
  271. s.sort = append(s.sort, fmt.Sprintf("%s:desc", field))
  272. }
  273. return s
  274. }
  275. // Stats specifies specific tag(s) of the request for logging and statistical purposes.
  276. func (s *DeleteByQueryService) Stats(stats ...string) *DeleteByQueryService {
  277. s.stats = append(s.stats, stats...)
  278. return s
  279. }
  280. // StoredFields specifies the list of stored fields to return as part of a hit.
  281. func (s *DeleteByQueryService) StoredFields(storedFields ...string) *DeleteByQueryService {
  282. s.storedFields = storedFields
  283. return s
  284. }
  285. // SuggestField specifies which field to use for suggestions.
  286. func (s *DeleteByQueryService) SuggestField(suggestField string) *DeleteByQueryService {
  287. s.suggestField = suggestField
  288. return s
  289. }
  290. // SuggestMode specifies the suggest mode. Possible values are
  291. // "missing", "popular", and "always".
  292. func (s *DeleteByQueryService) SuggestMode(suggestMode string) *DeleteByQueryService {
  293. s.suggestMode = suggestMode
  294. return s
  295. }
  296. // SuggestSize specifies how many suggestions to return in response.
  297. func (s *DeleteByQueryService) SuggestSize(suggestSize int) *DeleteByQueryService {
  298. s.suggestSize = &suggestSize
  299. return s
  300. }
  301. // SuggestText specifies the source text for which the suggestions should be returned.
  302. func (s *DeleteByQueryService) SuggestText(suggestText string) *DeleteByQueryService {
  303. s.suggestText = suggestText
  304. return s
  305. }
  306. // TerminateAfter indicates the maximum number of documents to collect
  307. // for each shard, upon reaching which the query execution will terminate early.
  308. func (s *DeleteByQueryService) TerminateAfter(terminateAfter int) *DeleteByQueryService {
  309. s.terminateAfter = &terminateAfter
  310. return s
  311. }
  312. // Timeout is the time each individual bulk request should wait for shards
  313. // that are unavailable.
  314. func (s *DeleteByQueryService) Timeout(timeout string) *DeleteByQueryService {
  315. s.timeout = timeout
  316. return s
  317. }
  318. // TimeoutInMillis sets the timeout in milliseconds.
  319. func (s *DeleteByQueryService) TimeoutInMillis(timeoutInMillis int) *DeleteByQueryService {
  320. s.timeout = fmt.Sprintf("%dms", timeoutInMillis)
  321. return s
  322. }
  323. // TrackScores indicates whether to calculate and return scores even if
  324. // they are not used for sorting.
  325. func (s *DeleteByQueryService) TrackScores(trackScores bool) *DeleteByQueryService {
  326. s.trackScores = &trackScores
  327. return s
  328. }
  329. // Version specifies whether to return document version as part of a hit.
  330. func (s *DeleteByQueryService) Version(version bool) *DeleteByQueryService {
  331. s.version = &version
  332. return s
  333. }
  334. // WaitForActiveShards sets the number of shard copies that must be active before proceeding
  335. // with the update by query operation. Defaults to 1, meaning the primary shard only.
  336. // Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal
  337. // to the total number of copies for the shard (number of replicas + 1).
  338. func (s *DeleteByQueryService) WaitForActiveShards(waitForActiveShards string) *DeleteByQueryService {
  339. s.waitForActiveShards = waitForActiveShards
  340. return s
  341. }
  342. // WaitForCompletion indicates if the request should block until the reindex is complete.
  343. func (s *DeleteByQueryService) WaitForCompletion(waitForCompletion bool) *DeleteByQueryService {
  344. s.waitForCompletion = &waitForCompletion
  345. return s
  346. }
  347. // Pretty indents the JSON output from Elasticsearch.
  348. func (s *DeleteByQueryService) Pretty(pretty bool) *DeleteByQueryService {
  349. s.pretty = pretty
  350. return s
  351. }
  352. // Body specifies the body of the request. It overrides data being specified via SearchService.
  353. func (s *DeleteByQueryService) Body(body string) *DeleteByQueryService {
  354. s.body = body
  355. return s
  356. }
  357. // buildURL builds the URL for the operation.
  358. func (s *DeleteByQueryService) buildURL() (string, url.Values, error) {
  359. // Build URL
  360. var err error
  361. var path string
  362. if len(s.typ) > 0 {
  363. path, err = uritemplates.Expand("/{index}/{type}/_delete_by_query", map[string]string{
  364. "index": strings.Join(s.index, ","),
  365. "type": strings.Join(s.typ, ","),
  366. })
  367. } else {
  368. path, err = uritemplates.Expand("/{index}/_delete_by_query", map[string]string{
  369. "index": strings.Join(s.index, ","),
  370. })
  371. }
  372. if err != nil {
  373. return "", url.Values{}, err
  374. }
  375. // Add query string parameters
  376. params := url.Values{}
  377. if len(s.xSource) > 0 {
  378. params.Set("_source", strings.Join(s.xSource, ","))
  379. }
  380. if len(s.xSourceExclude) > 0 {
  381. params.Set("_source_exclude", strings.Join(s.xSourceExclude, ","))
  382. }
  383. if len(s.xSourceInclude) > 0 {
  384. params.Set("_source_include", strings.Join(s.xSourceInclude, ","))
  385. }
  386. if s.analyzer != "" {
  387. params.Set("analyzer", s.analyzer)
  388. }
  389. if s.analyzeWildcard != nil {
  390. params.Set("analyze_wildcard", fmt.Sprintf("%v", *s.analyzeWildcard))
  391. }
  392. if s.defaultOperator != "" {
  393. params.Set("default_operator", s.defaultOperator)
  394. }
  395. if s.df != "" {
  396. params.Set("df", s.df)
  397. }
  398. if s.explain != nil {
  399. params.Set("explain", fmt.Sprintf("%v", *s.explain))
  400. }
  401. if len(s.storedFields) > 0 {
  402. params.Set("stored_fields", strings.Join(s.storedFields, ","))
  403. }
  404. if len(s.docvalueFields) > 0 {
  405. params.Set("docvalue_fields", strings.Join(s.docvalueFields, ","))
  406. }
  407. if s.from != nil {
  408. params.Set("from", fmt.Sprintf("%d", *s.from))
  409. }
  410. if s.ignoreUnavailable != nil {
  411. params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable))
  412. }
  413. if s.allowNoIndices != nil {
  414. params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices))
  415. }
  416. if s.conflicts != "" {
  417. params.Set("conflicts", s.conflicts)
  418. }
  419. if s.expandWildcards != "" {
  420. params.Set("expand_wildcards", s.expandWildcards)
  421. }
  422. if s.lenient != nil {
  423. params.Set("lenient", fmt.Sprintf("%v", *s.lenient))
  424. }
  425. if s.lowercaseExpandedTerms != nil {
  426. params.Set("lowercase_expanded_terms", fmt.Sprintf("%v", *s.lowercaseExpandedTerms))
  427. }
  428. if s.preference != "" {
  429. params.Set("preference", s.preference)
  430. }
  431. if s.q != "" {
  432. params.Set("q", s.q)
  433. }
  434. if len(s.routing) > 0 {
  435. params.Set("routing", strings.Join(s.routing, ","))
  436. }
  437. if s.scroll != "" {
  438. params.Set("scroll", s.scroll)
  439. }
  440. if s.searchType != "" {
  441. params.Set("search_type", s.searchType)
  442. }
  443. if s.searchTimeout != "" {
  444. params.Set("search_timeout", s.searchTimeout)
  445. }
  446. if s.size != nil {
  447. params.Set("size", fmt.Sprintf("%d", *s.size))
  448. }
  449. if len(s.sort) > 0 {
  450. params.Set("sort", strings.Join(s.sort, ","))
  451. }
  452. if s.terminateAfter != nil {
  453. params.Set("terminate_after", fmt.Sprintf("%v", *s.terminateAfter))
  454. }
  455. if len(s.stats) > 0 {
  456. params.Set("stats", strings.Join(s.stats, ","))
  457. }
  458. if s.suggestField != "" {
  459. params.Set("suggest_field", s.suggestField)
  460. }
  461. if s.suggestMode != "" {
  462. params.Set("suggest_mode", s.suggestMode)
  463. }
  464. if s.suggestSize != nil {
  465. params.Set("suggest_size", fmt.Sprintf("%v", *s.suggestSize))
  466. }
  467. if s.suggestText != "" {
  468. params.Set("suggest_text", s.suggestText)
  469. }
  470. if s.timeout != "" {
  471. params.Set("timeout", s.timeout)
  472. }
  473. if s.trackScores != nil {
  474. params.Set("track_scores", fmt.Sprintf("%v", *s.trackScores))
  475. }
  476. if s.version != nil {
  477. params.Set("version", fmt.Sprintf("%v", *s.version))
  478. }
  479. if s.requestCache != nil {
  480. params.Set("request_cache", fmt.Sprintf("%v", *s.requestCache))
  481. }
  482. if s.refresh != "" {
  483. params.Set("refresh", s.refresh)
  484. }
  485. if s.waitForActiveShards != "" {
  486. params.Set("wait_for_active_shards", s.waitForActiveShards)
  487. }
  488. if s.scrollSize != nil {
  489. params.Set("scroll_size", fmt.Sprintf("%d", *s.scrollSize))
  490. }
  491. if s.waitForCompletion != nil {
  492. params.Set("wait_for_completion", fmt.Sprintf("%v", *s.waitForCompletion))
  493. }
  494. if s.requestsPerSecond != nil {
  495. params.Set("requests_per_second", fmt.Sprintf("%v", *s.requestsPerSecond))
  496. }
  497. if s.pretty {
  498. params.Set("pretty", fmt.Sprintf("%v", s.pretty))
  499. }
  500. return path, params, nil
  501. }
  502. // Validate checks if the operation is valid.
  503. func (s *DeleteByQueryService) Validate() error {
  504. var invalid []string
  505. if len(s.index) == 0 {
  506. invalid = append(invalid, "Index")
  507. }
  508. if len(invalid) > 0 {
  509. return fmt.Errorf("missing required fields: %v", invalid)
  510. }
  511. return nil
  512. }
  513. // Do executes the delete-by-query operation.
  514. func (s *DeleteByQueryService) Do(ctx context.Context) (*BulkIndexByScrollResponse, error) {
  515. // Check pre-conditions
  516. if err := s.Validate(); err != nil {
  517. return nil, err
  518. }
  519. // Get URL for request
  520. path, params, err := s.buildURL()
  521. if err != nil {
  522. return nil, err
  523. }
  524. // Set body if there is a query set
  525. var body interface{}
  526. if s.body != nil {
  527. body = s.body
  528. } else if s.query != nil {
  529. src, err := s.query.Source()
  530. if err != nil {
  531. return nil, err
  532. }
  533. body = map[string]interface{}{
  534. "query": src,
  535. }
  536. }
  537. // Get response
  538. res, err := s.client.PerformRequest(ctx, "POST", path, params, body)
  539. if err != nil {
  540. return nil, err
  541. }
  542. // Return result
  543. ret := new(BulkIndexByScrollResponse)
  544. if err := s.client.decoder.Decode(res.Body, ret); err != nil {
  545. return nil, err
  546. }
  547. return ret, nil
  548. }
  549. // BulkIndexByScrollResponse is the outcome of executing Do with
  550. // DeleteByQueryService and UpdateByQueryService.
  551. type BulkIndexByScrollResponse struct {
  552. Took int64 `json:"took"`
  553. SliceId *int64 `json:"slice_id,omitempty"`
  554. TimedOut bool `json:"timed_out"`
  555. Total int64 `json:"total"`
  556. Updated int64 `json:"updated,omitempty"`
  557. Created int64 `json:"created,omitempty"`
  558. Deleted int64 `json:"deleted"`
  559. Batches int64 `json:"batches"`
  560. VersionConflicts int64 `json:"version_conflicts"`
  561. Noops int64 `json:"noops"`
  562. Retries struct {
  563. Bulk int64 `json:"bulk"`
  564. Search int64 `json:"search"`
  565. } `json:"retries,omitempty"`
  566. Throttled string `json:"throttled"`
  567. ThrottledMillis int64 `json:"throttled_millis"`
  568. RequestsPerSecond float64 `json:"requests_per_second"`
  569. Canceled string `json:"canceled,omitempty"`
  570. ThrottledUntil string `json:"throttled_until"`
  571. ThrottledUntilMillis int64 `json:"throttled_until_millis"`
  572. Failures []bulkIndexByScrollResponseFailure `json:"failures"`
  573. }
  574. type bulkIndexByScrollResponseFailure struct {
  575. Index string `json:"index,omitempty"`
  576. Type string `json:"type,omitempty"`
  577. Id string `json:"id,omitempty"`
  578. Status int `json:"status,omitempty"`
  579. Shard int `json:"shard,omitempty"`
  580. Node int `json:"node,omitempty"`
  581. // TOOD "cause" contains exception details
  582. // TOOD "reason" contains exception details
  583. }