Skip to content

Commit

Permalink
fix: improve es compatible (zincsearch#493)
Browse files Browse the repository at this point in the history
* fix: improve es compatible

* doc: Bump go mod version
  • Loading branch information
hengfeiyang authored Aug 31, 2022
1 parent 51892d4 commit a72b06d
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 32 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/zinclabs/zinc
go 1.16

require (
github.com/aws/aws-sdk-go-v2/config v1.17.2
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.6
github.com/aws/aws-sdk-go-v2/config v1.17.3
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.7
github.com/blugelabs/bluge v0.1.9
github.com/blugelabs/bluge_segment_api v0.2.0
github.com/blugelabs/ice v1.0.0
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ github.com/aws/aws-sdk-go-v2 v1.16.12 h1:wbMYa2PlFysFx2GLIQojr6FJV5+OWCM/BwyHXAR
github.com/aws/aws-sdk-go-v2 v1.16.12/go.mod h1:C+Ym0ag2LIghJbXhfXZ0YEEp49rBWowxKzJLUoob0ts=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.5 h1:7A1nDFvkVlBmMa69QMLkw/m/DDHm6PUluIYK61aQoOY=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.5/go.mod h1:DnlOnWR2YuzMXNSHHNuoklObUE3SwWlcRTGL/zL+Aj8=
github.com/aws/aws-sdk-go-v2/config v1.17.2 h1:V96WPd2a1H/MXGZjk4zto+KpYnwZI2kdIdy/cI8kYnQ=
github.com/aws/aws-sdk-go-v2/config v1.17.2/go.mod h1:jumS/AMwul4WaG8vyXsF6kUndG9zndR+yfYBwl4i9ds=
github.com/aws/aws-sdk-go-v2/credentials v1.12.15 h1:6DONxG9cR3pAuISj1Irh5u2SRqCfIJwyHNyDDes7SZw=
github.com/aws/aws-sdk-go-v2/credentials v1.12.15/go.mod h1:41zTC6U/78fUD7ZCa5NymTJANDjfqySg5YEAYVFl2Ic=
github.com/aws/aws-sdk-go-v2/config v1.17.3 h1:s1As/fiVMmM3CObC4GcSaSbkhm88S6a5qn8St3wgal0=
github.com/aws/aws-sdk-go-v2/config v1.17.3/go.mod h1:tRGUOfk9Rrf6UCJm5qDlL9AizSsgvteuKX4qajAV3pU=
github.com/aws/aws-sdk-go-v2/credentials v1.12.16 h1:HXczS88Pg36j8dq0KSjtHBPFs8gdRyBSS1hueeG/rxA=
github.com/aws/aws-sdk-go-v2/credentials v1.12.16/go.mod h1:eLJ+j1lwQdHJ0c56tRoDWcgss1e/laVmvW2AaOicuAw=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.13 h1:+uferi8SUDZtMloCDt24Zenyy/i71C/ua5mjUCpbpN0=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.13/go.mod h1:y0eXmsNBFIVjUE8ZBjES8myOHlMsXDz7qGT93+MVdjk=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.19 h1:gC5mudiFrWGhzcdoWj1iCGUfrzCpQG0MQIQf0CXFFQQ=
Expand All @@ -84,14 +84,14 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.13 h1:ObfthqDyh
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.13/go.mod h1:V390DK4MQxLpDdXxFqizyz8KUxuWImkW/xzgXMz0yyk=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.13 h1:h1equp9qdWANft5cmtDUditRlALvE7tuaHs2RdSbsQg=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.13/go.mod h1:3RA7cs1uHkbV3f6tMYy7u0OfkyVckZBM70wUS4h1MDk=
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.6 h1:4+iM+rBAcS9zZwQ2+Y57GgC41cRe6C8khdYfqaUT2k0=
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.6/go.mod h1:orjy5IRgBQnh9EI/lMW7YGF6eYk6re8HPFbL66a2DSo=
github.com/aws/aws-sdk-go-v2/service/sso v1.11.18 h1:gTn1a/FbcOXK5LQS88dD5k+PKwyjVvhAEEwyN4c6eW8=
github.com/aws/aws-sdk-go-v2/service/sso v1.11.18/go.mod h1:ytmEi5+qwcSNcV2pVA8PIb1DnKT/0Bu/K4nfJHwoM6c=
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.7 h1:BlxqVULzNS7udJIwZBJdL8NNcLbSwgXv/WRJCVUaMm8=
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.7/go.mod h1:orjy5IRgBQnh9EI/lMW7YGF6eYk6re8HPFbL66a2DSo=
github.com/aws/aws-sdk-go-v2/service/sso v1.11.19 h1:WdCwfJmu23XiIDeZwclSyAorQe916M3LeHd53xqBjfA=
github.com/aws/aws-sdk-go-v2/service/sso v1.11.19/go.mod h1:ytmEi5+qwcSNcV2pVA8PIb1DnKT/0Bu/K4nfJHwoM6c=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.1 h1:p48IfndYbRk3iDsoQAmVXdCKEM5+7Y50JAPikjwk8gI=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.1/go.mod h1:NY+G+8PW0ISyJ7/6t5mgOe6qpJiwZa9Jix05WPscJjg=
github.com/aws/aws-sdk-go-v2/service/sts v1.16.14 h1:7kxso8VZLQ86Jg27QRBw6fjrQhQ8CMNMZ7SB0w7RQiA=
github.com/aws/aws-sdk-go-v2/service/sts v1.16.14/go.mod h1:Y+BUV19q3OmQVqNUlbZ40zVi3NM6Biuxwkx/qdSD/CY=
github.com/aws/aws-sdk-go-v2/service/sts v1.16.15 h1:ApuR2BK9vf5/XXsImHBBsYJ6aUhmUhBHnZMPyhJo1jQ=
github.com/aws/aws-sdk-go-v2/service/sts v1.16.15/go.mod h1:Y+BUV19q3OmQVqNUlbZ40zVi3NM6Biuxwkx/qdSD/CY=
github.com/aws/smithy-go v1.13.0 h1:YfyEmSJLo7fAv8FbuDK4R8F9aAmi9DZ88Zb/KJJmUl0=
github.com/aws/smithy-go v1.13.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/axiomhq/hyperloglog v0.0.0-20191112132149-a4c4c47bc57f h1:y06x6vGnFYfXUoVMbrcP1Uzpj4JG01eB5vRps9G8agM=
Expand Down
11 changes: 10 additions & 1 deletion pkg/handlers/document/create_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,16 @@ func CreateUpdate(c *gin.Context) {
c.JSON(http.StatusInternalServerError, meta.HTTPResponseError{Error: err.Error()})
return
}
c.JSON(http.StatusOK, meta.HTTPResponseID{Message: "ok", ID: docID})
c.JSON(http.StatusOK, meta.HTTPResponseESID{
Message: "ok",
ID: docID,
ESID: docID,
Index: indexName,
Version: 1,
SeqNo: 0,
PrimaryTerm: 0,
Result: "created",
})
}

// @Id IndexDocumentWithID
Expand Down
11 changes: 11 additions & 0 deletions pkg/meta/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ type HTTPResponseRecordCount struct {
type HTTPResponseError struct {
Error string `json:"error"`
}

type HTTPResponseESID struct {
Message string `json:"message"`
ID string `json:"id"`
ESID string `json:"_id"`
Index string `json:"_index"`
Version int `json:"_version"`
SeqNo int `json:"_seq_no"`
PrimaryTerm int `json:"_primary_term"`
Result string `json:"result"` // created, updated, deleted
}
3 changes: 1 addition & 2 deletions pkg/uquery/fields/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package fields

import (
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -45,7 +44,7 @@ func Request(v []interface{}) ([]*meta.Field, error) {
case "format":
f.Format = v.(string)
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[fields] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[fields] unknown field [%s]", k))
}
}
fields = append(fields, f)
Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/query/fuzzy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func FuzzyQuery(query map[string]interface{}, mappings *meta.Mappings, analyzers
case "boost":
value.Boost, _ = zutils.ToFloat64(v)
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[fuzzy] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[fuzzy] unknown field [%s]", k))
}
}
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/query/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func IdsQuery(query map[string]interface{}, mappings *meta.Mappings) (bluge.Quer
return nil, errors.New(errors.ErrorTypeXContentParseException, fmt.Sprintf("[ids] %s doesn't support values of type: %T", k, v))
}
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[ids] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[ids] unknown field [%s]", k))
}
}
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/query/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func MatchQuery(query map[string]interface{}, mappings *meta.Mappings, analyzers
case "boost":
value.Boost, _ = zutils.ToFloat64(v)
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[match] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[match] unknown field [%s]", k))
}
}
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/query/match_bool_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func MatchBoolPrefixQuery(query map[string]interface{}, mappings *meta.Mappings,
case "boost":
value.Boost = v.(float64)
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[match_bool_prefix] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[match_bool_prefix] unknown field [%s]", k))
}
}
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/query/match_phrase.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func MatchPhraseQuery(query map[string]interface{}, mappings *meta.Mappings, ana
case "boost":
value.Boost = v.(float64)
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[match_phrase] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[match_phrase] unknown field [%s]", k))
}
}
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/query/match_phrase_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func MatchPhrasePrefixQuery(query map[string]interface{}, mappings *meta.Mapping
case "boost":
value.Boost = v.(float64)
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[match_phrase_prefix] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[match_phrase_prefix] unknown field [%s]", k))
}
}
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/query/multi_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func MultiMatchQuery(query map[string]interface{}, mappings *meta.Mappings, anal
return nil, errors.New(errors.ErrorTypeXContentParseException, fmt.Sprintf("[multi_match] %s doesn't support values of type: %T", k, v))
}
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[multi_match] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[multi_match] unknown field [%s]", k))
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/query/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func PrefixQuery(query map[string]interface{}) (bluge.Query, error) {
case "boost":
value.Boost = v.(float64)
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[prefix] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[prefix] unknown field [%s]", k))
}
}
default:
Expand Down
4 changes: 2 additions & 2 deletions pkg/uquery/query/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func RangeQueryNumeric(field string, query map[string]interface{}, mappings *met
case "boost":
value.Boost, _ = zutils.ToFloat64(v)
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[range] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[range] unknown field [%s]", k))
}
}

Expand Down Expand Up @@ -125,7 +125,7 @@ func RangeQueryTime(field string, query map[string]interface{}, mappings *meta.M
case "boost":
value.Boost, _ = zutils.ToFloat64(v)
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[range] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[range] unknown field [%s]", k))
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/query/regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func RegexpQuery(query map[string]interface{}) (bluge.Query, error) {
case "boost":
value.Boost = v.(float64)
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[regexp] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[regexp] unknown field [%s]", k))
}
}
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/query/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TermQuery(query map[string]interface{}, mappings *meta.Mappings) (bluge.Que
case "boost":
value.Boost = v.(float64)
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[term] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[term] unknown field [%s]", k))
}
}
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/query/wildcard.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func WildcardQuery(query map[string]interface{}) (bluge.Query, error) {
case "boost":
value.Boost = v.(float64)
default:
return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[wildcard] unknown field [%s]", k))
// return nil, errors.New(errors.ErrorTypeParsingException, fmt.Sprintf("[wildcard] unknown field [%s]", k))
}
}
default:
Expand Down
4 changes: 2 additions & 2 deletions test/api/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func TestDocument(t *testing.T) {
resp := request("PUT", "/api/"+indexName+"/_doc", body)
assert.Equal(t, http.StatusOK, resp.Code)

data := make(map[string]string)
data := make(map[string]interface{})
err := json.Unmarshal(resp.Body.Bytes(), &data)
assert.NoError(t, err)
assert.NotEqual(t, "", data["id"])
_id = data["id"]
_id = data["id"].(string)
})
t.Run("update document with exist indexName and exist id", func(t *testing.T) {
body := bytes.NewBuffer(nil)
Expand Down
4 changes: 2 additions & 2 deletions test/api/es_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ func TestApiES(t *testing.T) {
resp := request("POST", "/es/"+indexName+"/_doc", body)
assert.Equal(t, http.StatusOK, resp.Code)

data := make(map[string]string)
data := make(map[string]interface{})
err := json.Unmarshal(resp.Body.Bytes(), &data)
assert.NoError(t, err)
assert.NotEqual(t, "", data["id"])
_id = data["id"]
_id = data["id"].(string)
})
t.Run("update document with exist indexName and exist id", func(t *testing.T) {
body := bytes.NewBuffer(nil)
Expand Down

0 comments on commit a72b06d

Please sign in to comment.