Debian Codegraph @

search_queries_slice.go

raw
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
5 package elastic
6
7 // SliceQuery allows to partition the documents into several slices.
8 // It is used e.g. to slice scroll operations in Elasticsearch 5.0 or later.
9 // See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-scroll.html#sliced-scroll
10 // for details.
11 type SliceQuery struct {
12 field string
13 id *int
14 max *int
15 }
16
17 // NewSliceQuery creates a new SliceQuery.
18 func NewSliceQuery() *SliceQuery {
19 return &SliceQuery{}
20 }
21
22 // Field is the name of the field to slice against (_uid by default).
23 func (s *SliceQuery) Field(field string) *SliceQuery {
24 s.field = field
25 return s
26 }
27
28 // Id is the id of the slice.
29 func (s *SliceQuery) Id(id int) *SliceQuery {
30 s.id = &id
31 return s
32 }
33
34 // Max is the maximum number of slices.
35 func (s *SliceQuery) Max(max int) *SliceQuery {
36 s.max = &max
37 return s
38 }
39
40 // Source returns the JSON body.
41 func (s *SliceQuery) Source() (interface{}, error) {
42 m := make(map[string]interface{})
43 if s.field != "" {
44 m["field"] = s.field
45 }
46 if s.id != nil {
47 m["id"] = *s.id
48 }
49 if s.max != nil {
50 m["max"] = *s.max
51 }
52 return m, nil
53 }