Skip to content

Commit

Permalink
UTC for date-filter, wildcard for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris committed Nov 15, 2024
1 parent f919184 commit 51f12e9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
10 changes: 6 additions & 4 deletions front/assets/js/app-search.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const date = new Date();
const dateS = new Date();
const dateE = new Date();
var mapping = [];
var fmapping = {};
var filter_operation = ["is", "is_not", "exists", "does_not_exists"]
var filters_set = {}
date.setMinutes(date.getMinutes() - 15)
dateS.setMinutes(dateS.getMinutes() - 195)
dateE.setMinutes(dateE.getMinutes() - 180)
$.datetimepicker.setLocale('ru');
$('#datetimepicker_start').datetimepicker({timepicker: true, format:'Y-m-d H:i:s', step: 15, value:date});
$('#datetimepicker_start').datetimepicker({timepicker: true, format:'Y-m-d H:i:s', step: 15, value:dateS});
$('#datetimepicker_end').datetimepicker({
timepicker: true,
format:'Y-m-d H:i:s',
step: 15,
value:new Date(),
value:dateE,
onShow:function( ct ){
this.setOptions({
minDate:$('#datetimepicker_start').val()?$('#datetimepicker_start').val():false
Expand Down
21 changes: 19 additions & 2 deletions modules/router/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func (rt *Router) getIndexGroups(cluster string) ([]indexGroup, error) {
return nil, err
}
err = json.Unmarshal(response, &igs)
fmt.Printf("%v\n", igs)
if err != nil {
return nil, err
}
Expand All @@ -244,8 +245,9 @@ func (rt *Router) getIndexGroups(cluster string) ([]indexGroup, error) {
n.Index = match[1] + "-*"
igresp = append(igresp, n)
}

return igresp, nil
unique := removeDuplicates(igresp)
fmt.Printf("%v\n", unique)
return unique, nil

}

Expand Down Expand Up @@ -319,3 +321,18 @@ func allocateSpaceForFile(path string, size int64) {
log.Fatal(err)
}
}

func removeDuplicates(slice []indexGroup) []indexGroup {
// Create a map to store unique elements
seen := make(map[indexGroup]bool)
var result []indexGroup

// Loop through the slice, adding elements to the map if they haven't been seen before
for _, val := range slice {
if _, ok := seen[val]; !ok {
seen[val] = true
result = append(result, val)
}
}
return result
}
7 changes: 3 additions & 4 deletions modules/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
for _, f := range request.Search.Filters {

if f.Operation == "is" {
filters += `{ "match_phrase": {"` + f.Field + `":"` + f.Value + `" } },`
filters += `{ "wildcard": {"` + f.Field + `": {"value": "` + f.Value + `" } } },`
} else if f.Operation == "exists" {
filters += `{ "exists": {"field":"` + f.Field + `" } },`
} else if f.Operation == "is_not" {
Expand Down Expand Up @@ -684,7 +684,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
query = fmt.Sprintf(`"query": { "bool": { "must": [ %s ],"filter": [ %s %s ], "should": [],"must_not": [ %s ] }}`, xql, tf, filters, must_not)

full_query = fmt.Sprintf(`{"size": 500, %s, %s, %s, %s }`, sort, use_source, fields, query)

fmt.Println(full_query)
if request.Search.Count {
_ = json.Unmarshal([]byte("{"+query+"}"), &req)
cresponse, err := rt.doPost(host+request.Search.Index+"/_count", req, "Search")
Expand Down Expand Up @@ -747,7 +747,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
for _, f := range request.Search.Filters {

if f.Operation == "is" {
filters += `{ "match_phrase": {"` + f.Field + `":"` + f.Value + `" } },`
filters += `{ "wildcard": {"` + f.Field + `": {"value": "` + f.Value + `" } } },`
} else if f.Operation == "exists" {
filters += `{ "exists": {"field":"` + f.Field + `" } },`
} else if f.Operation == "is_not" {
Expand Down Expand Up @@ -778,7 +778,6 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
query = fmt.Sprintf(`"query": { "bool": { "must": [ %s ],"filter": [ %s %s ], "should": [],"must_not": [ %s ] }}`, xql, tf, filters, must_not)

full_query = fmt.Sprintf(`{"size": 10000, %s, %s, %s, %s }`, sort, use_source, fields, query)
//fmt.Println(full_query)

err = json.Unmarshal([]byte(full_query), &req)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion modules/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

package version

var Version = "extractor/v0.2.13"
var Version = "extractor/v0.2.14"

0 comments on commit 51f12e9

Please sign in to comment.