MCPcopy
hub / github.com/zincsearch/zincsearch / SearchDSL

Function SearchDSL

pkg/handlers/search/search_v2.go:48–80  ·  view source on GitHub ↗

SearchDSL searches the index for the given http request from end user @Id Search @Summary Search V2 DSL for compatible ES @security BasicAuth @Tags Search @Accept json @Produce json @Param index path string true "Index" @Param query body meta.ZincQueryForSDK true "Query" @Success 200

(c *gin.Context)

Source from the content-addressed store, hash-verified

46// @Failure 400 {object} meta.HTTPResponseError
47// @Router /es/{index}/_search [post]
48func SearchDSL(c *gin.Context) {
49 indexName := c.Param("target")
50
51 query := &meta.ZincQuery{Size: 10}
52 if err := zutils.GinBindJSON(c, query); err != nil {
53 log.Printf("handlers.search.searchDSL: %s", err.Error())
54 zutils.GinRenderJSON(c, http.StatusBadRequest, meta.HTTPResponseError{Error: err.Error()})
55 return
56 }
57
58 resp, err := searchIndex(strings.Split(indexName, ","), query)
59 if err != nil {
60 errors.HandleError(c, err)
61 return
62 }
63
64 if indexName != "" {
65 // TODO: adapt this to allow strings.Split(indexName, ",") slice
66 idx, ok := core.ZINC_INDEX_LIST.Get(indexName)
67 if ok {
68 storageSize := idx.GetStats().StorageSize
69 eventData := make(map[string]interface{})
70 eventData["search_type"] = "query_dsl"
71 eventData["search_index_storage"] = idx.GetStorageType()
72 eventData["search_index_size_in_mb"] = storageSize / 1024 / 1024
73 eventData["time_taken_to_search_in_ms"] = resp.Took
74 eventData["aggregations_count"] = len(query.Aggregations)
75 core.Telemetry.Event("search", eventData)
76 }
77 }
78
79 zutils.GinRenderJSON(c, http.StatusOK, resp)
80}
81
82// MultipleSearch like bulk searches
83//

Callers 1

TestSearchDSLFunction · 0.85

Calls 9

GinBindJSONFunction · 0.92
GinRenderJSONFunction · 0.92
HandleErrorFunction · 0.92
searchIndexFunction · 0.85
ErrorMethod · 0.80
GetStatsMethod · 0.80
GetStorageTypeMethod · 0.80
EventMethod · 0.80
GetMethod · 0.65

Tested by 1

TestSearchDSLFunction · 0.68