Skip to content

Commit

Permalink
feat: add index health API and fix some bugs (#253)
Browse files Browse the repository at this point in the history
* fix: add health API and fix some bugs

* fix: fix ut case
  • Loading branch information
xiangwanpeng authored Jul 14, 2023
1 parent 06be819 commit f163c36
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions internal/common/utils/type_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func IsDateType(value interface{}) bool {
_, err := now.Parse(value)
return err == nil
case int64:
return value > 1e12
return value >= 0
case float64:
return value > 1e12
return value >= 0
default:
return false
}
Expand Down
12 changes: 6 additions & 6 deletions internal/core/core_test/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,6 @@ func TestCheckDocuments(t *testing.T) {
Type: consts.MappingFieldTypeKeyword,
},
}},
{"date_as_keyword": &protocol.DynamicTemplate{
MatchMappingType: consts.JSONFieldTypeDate,
Mapping: &protocol.DynamicTemplateMapping{
Type: consts.MappingFieldTypeKeyword,
},
}},
{"long_as_integer": &protocol.DynamicTemplate{
MatchMappingType: consts.JSONFieldTypeLong,
Mapping: &protocol.DynamicTemplateMapping{
Expand All @@ -265,6 +259,12 @@ func TestCheckDocuments(t *testing.T) {
Type: consts.MappingFieldTypeDouble,
},
}},
{"date_as_keyword": &protocol.DynamicTemplate{
MatchMappingType: consts.JSONFieldTypeDate,
Mapping: &protocol.DynamicTemplateMapping{
Type: consts.MappingFieldTypeKeyword,
},
}},
},
Properties: map[string]*protocol.Property{
consts.IDField: {Type: consts.MappingFieldTypeKeyword},
Expand Down
3 changes: 2 additions & 1 deletion internal/indexlib/bluge/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (b *BlugeWriter) generateBlugeDoc(
doc protocol.Document,
mappings protocol.Mappings,
) (segment.Document, error) {
ts, _ := utils.ParseTime(doc[consts.TimestampField])
bdoc := bluge.NewDocument(docID)
for key, value := range doc {
if value == nil {
Expand Down Expand Up @@ -147,7 +148,7 @@ func (b *BlugeWriter) generateBlugeDoc(
bdoc.AddField(bluge.NewStoredOnlyField(consts.IndexField, []byte(b.Index)))
bdoc.AddField(bluge.NewStoredOnlyField(consts.SourceField, source))
bdoc.AddField(
bluge.NewDateTimeField(consts.TimestampField, time.Now()).
bluge.NewDateTimeField(consts.TimestampField, ts).
Sortable().
Aggregatable(),
)
Expand Down
1 change: 1 addition & 0 deletions internal/service/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func registerMeta(group *gin.RouterGroup) {
group.GET("/_nodes/_all", handler.ClusterNodesInfoHandler)

group.GET("/_cluster/health", handler.ClusterStatusHandler)
group.GET("/_cluster/health/:index", handler.ClusterStatusHandler)

group.PUT("/:index", handler.CreateIndexHandler)
group.POST("/:index", handler.CreateIndexHandler)
Expand Down

0 comments on commit f163c36

Please sign in to comment.