Skip to content

Commit

Permalink
MB-27696: Allow a unique ID to be set for a Search Request (#1858)
Browse files Browse the repository at this point in the history
Add a unique ID for a bleve Search Request which will be echo'd back in
the Search Result. Would be useful in a parallel search query scenario
to differentiate between the queries.

---------

Co-authored-by: Abhi Dangeti <[email protected]>
  • Loading branch information
CascadingRadium and abhinavdangeti authored Sep 8, 2023
1 parent 81c11e1 commit 2267798
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ func (h *HighlightRequest) AddField(field string) {
//
// A special field named "*" can be used to return all fields.
type SearchRequest struct {
ClientContextID string `json:"client_context_id,omitempty"`
Query query.Query `json:"query"`
Size int `json:"size"`
From int `json:"from"`
Expand All @@ -321,6 +322,10 @@ type SearchRequest struct {
sortFunc func(sort.Interface)
}

func (r *SearchRequest) SetClientContextID(id string) {
r.ClientContextID = id
}

func (r *SearchRequest) Validate() error {
if srq, ok := r.Query.(query.ValidatableQuery); ok {
if err := srq.Validate(); err != nil {
Expand Down Expand Up @@ -392,6 +397,7 @@ func (r *SearchRequest) SetSearchBefore(before []string) {
func (r *SearchRequest) UnmarshalJSON(input []byte) error {
var (
temp struct {
ClientContextID string `json:"client_context_id"`
Q json.RawMessage `json:"query"`
Size *int `json:"size"`
From int `json:"from"`
Expand Down Expand Up @@ -424,6 +430,7 @@ func (r *SearchRequest) UnmarshalJSON(input []byte) error {
return err
}
}
r.ClientContextID = temp.ClientContextID
r.From = temp.From
r.Explain = temp.Explain
r.Highlight = temp.Highlight
Expand Down

0 comments on commit 2267798

Please sign in to comment.