github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/docs/search.md (about) 1 # Search 2 3 API to search data with the specified criteria. 4 5 ## Params 6 7 | Parameter | Description | Type | 8 | ------------ | ------------------------------------------ | --------------- | 9 | `ctx` | Context to control API invocation process. | context.Context | 10 | `collName` | Name of the collection to search in. | String | 11 | `partitions` | List of names of the partitions to search in. </br>If empty, all partition will be searched. | Slice of string | 12 | `expr` | Boolean expression to filter the data. | String | 13 | `outputFields` | List of names of fields to output. | Slice of string | 14 | `vectors` | Vectors to search with. | Slice of entity.Vector | 15 | `metricType` | Metric type to calculate distance with. | entity.MetricType | 16 | `topK` | Number of nearest records to return. | INT | 17 | `sp` | Specific search parameter(s) that related to the index type the vector field has. | entity.SearchParam | 18 19 20 21 ## Response 22 23 - `results`: slice of SearchResult that contains the search result, one record per vector. 24 25 - `err`: error in the process (if any). Possible errors are listed below: 26 27 - `ErrClientNotReady`, error that the client is not connected. 28 29 - `ErrCollectionNotExists`, error that collection with the specified name does not exist. 30 31 - error that API invocation failed. 32 33 ## Example 34 35 ```go 36 ctx := context.Background() 37 // vector is the vector to search 38 // Use flat search param 39 sp, _ := entity.NewIndexFlatSearchParam(10) 40 // cli is a valid Client instance 41 sr, err := c.Search(ctx, collectionName, []string{}, "Year > 1990", []string{"ID"}, []entity.Vector{vector}, "Vector", 42 entity.L2, 10, sp) 43 // some example code to process SearchResult 44 for _, result := range sr { 45 var idColumn *entity.ColumnInt64 46 for _, field := range result.Fields { 47 if field.Name() == "ID" { 48 c, ok := field.(*entity.ColumnInt64) 49 if ok { 50 idColumn = c 51 } 52 } 53 } 54 if idColumn == nil { 55 log.Fatal("result field not math") 56 } 57 for i := 0; i < result.ResultCount; i++ { 58 id, err := idColumn.ValueByIdx(i) 59 if err != nil { 60 log.Fatal(err.Error()) 61 } 62 title := idTitle[id] 63 fmt.Printf("file id: %d title: %s scores: %f\n", id, title, result.Scores[i]) 64 } 65 } 66 67 ```