/** * Replace new document in an index * Replace an existing document. Input has same format as `insert` operation. <br/> Responds with an object in format: <br/> ``` {'_index':'products','_id':1,'created':false,'result':'updated','status':200} ``` * @param insertDocumentRequest (required) * @return ApiResponse<SuccessResponse> * @throws ApiException if fails to make API call * @http.response.details * <table summary="Response Details" border="1"> * <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr> * <tr><td> 200 </td><td> OK </td><td> - </td></tr> * <tr><td> 0 </td><td> error </td><td> - </td></tr> * </table> * * @see <a href="https://docs.manticoresearch.com/latest/html/http_reference/json_insert.html">Replace new document in an index Documentation</a> */ public ApiResponse <SuccessResponse> ReplaceWithHttpInfo(InsertDocumentRequest insertDocumentRequest) { object localVarPostBody = insertDocumentRequest; // verify the required parameter 'insertDocumentRequest' is set if (insertDocumentRequest == null) { throw new ApiException(400, "Missing the required parameter 'insertDocumentRequest' when calling replace"); } // create path and Dictionary variables string localVarPath = "/json/replace"; // query params List <Pair> localVarQueryParams = new List <Pair>(); Dictionary <string, string> localVarHeaderParams = new Dictionary <string, string>(); Dictionary <string, string> localVarCookieParams = new Dictionary <string, string>(); Dictionary <string, object> localVarFormParams = new Dictionary <string, object>(); string[] localVarAccepts = { "application/json" }; string localVarAccept = apiClient.SelectHeaderAccept(localVarAccepts); string[] localVarContentTypes = { "application/json" }; string localVarContentType = apiClient.SelectHeaderContentType(localVarContentTypes); string[] localVarAuthNames = new string[] { }; SuccessResponse localVarReturnType = new SuccessResponse() { }; return(apiClient.InvokeAPI("IndexApi.replace", localVarPath, HttpMethod.Post, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType, false)); }
static void Main(string[] args) { try { var util = new UtilsApi(); var searchApi = new SearchApi(); var indexApi = new IndexApi(); Dictionary <string, object> result; try { result = util.Sql(@"query=select * from products"); foreach (var item in result) { Console.WriteLine($"{item.Key} - {item.Value}"); } } catch (Exception ex) { Console.WriteLine(ex); } var rs = util.Sql("mode=raw&query=create table products(title text, price float) morphology='stem_en'"); Console.WriteLine("Create result " + rs.Count + Environment.NewLine); rs = util.Sql("mode=raw&query=SELECT * FROM products"); Console.WriteLine("Select result " + rs.Count + Environment.NewLine); var newdoc = new InsertDocumentRequest(); Dictionary <string, object> doc = new Dictionary <string, object>(); doc.Add("title", "Crossbody Bag with Tassel"); doc.Add("price", 19.85); newdoc.Index("products").Id(0).SetDoc(doc); var insertResult = indexApi.Insert(newdoc); Console.WriteLine(insertResult + Environment.NewLine); newdoc = new InsertDocumentRequest(); doc = new Dictionary <string, object>(); doc.Add("title", "microfiber sheet set"); doc.Add("price", 19.99); newdoc.Index("products").Id(0).SetDoc(doc); insertResult = indexApi.Insert(newdoc); Console.WriteLine(insertResult + Environment.NewLine); newdoc = new InsertDocumentRequest(); doc = new Dictionary <string, object>(); doc.Add("title", "Pet Hair Remover Glove"); doc.Add("price", 7.99); newdoc.Index("products").Id(0L).SetDoc(doc); insertResult = indexApi.Insert(newdoc); Console.WriteLine(insertResult + Environment.NewLine); var query = new Dictionary <string, object>(); var match = new Dictionary <string, object>() { { "title", "crossbody" } }; query.Add("match", match); var searchRequest = new SearchRequest(); searchRequest.SetIndex("products"); searchRequest.SetQuery(query); Dictionary <string, object> highlight = new Dictionary <string, object>(); highlight.Add("fields", new string[] { "title" }); searchRequest.SetHighlight(highlight); var searchResponse = searchApi.Search(searchRequest); Console.WriteLine(searchResponse + Environment.NewLine); UpdateDocumentRequest updateRequest = new UpdateDocumentRequest(); doc = new Dictionary <string, object>(); doc.Add("price", 17.5); updateRequest.Index("products").Id(2L).SetDoc(doc); var updResult = indexApi.Update(updateRequest); Console.WriteLine(updResult + Environment.NewLine); DeleteDocumentRequest deleteRequest = new DeleteDocumentRequest(); var condition = new Dictionary <string, object>() { { "lte", 10 } }; var field = new Dictionary <string, object>() { { "price", condition } }; query = new Dictionary <string, object>() { { "range", field } }; deleteRequest.Index("products").SetQuery(query); var deleteResult = indexApi.Delete(deleteRequest); Console.WriteLine(deleteResult + Environment.NewLine); } catch (Exception ex) { Console.WriteLine(ex); } }
/** * Replace new document in an index * Replace an existing document. Input has same format as `insert` operation. <br/> Responds with an object in format: <br/> ``` {'_index':'products','_id':1,'created':false,'result':'updated','status':200} ``` * @param insertDocumentRequest (required) * @return SuccessResponse * @throws ApiException if fails to make API call * @http.response.details * <table summary="Response Details" border="1"> * <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr> * <tr><td> 200 </td><td> OK </td><td> - </td></tr> * <tr><td> 0 </td><td> error </td><td> - </td></tr> * </table> * * @see <a href="https://docs.manticoresearch.com/latest/html/http_reference/json_insert.html">Replace new document in an index Documentation</a> */ public SuccessResponse Replace(InsertDocumentRequest InsertDocumentRequest) { return(ReplaceWithHttpInfo(InsertDocumentRequest).GetData()); }
/** * Create a new document in an index * Insert a document. Expects an object like: ``` {'index':'movies','id':701,'doc':{'title':'This is an old movie','plot':'A secret team goes to North Pole','year':1950,'rating':9.5,'lat':60.4,'lon':51.99,'advise':'PG-13','meta':'{\"keywords\":{\"travel\",\"ice\"},\"genre\":{\"adventure\"}}','language':[2,3]}} ``` The document id can also be missing, in which case an autogenerated one will be used: ``` {'index':'movies','doc':{'title':'This is a new movie','plot':'A secret team goes to North Pole','year':2020,'rating':9.5,'lat':60.4,'lon':51.99,'advise':'PG-13','meta':'{\"keywords\":{\"travel\",\"ice\"},\"genre\":{\"adventure\"}}','language':[2,3]}} ``` It responds with an object in format: ``` {'_index':'products','_id':701,'created':true,'result':'created','status':201} ``` * @param insertDocumentRequest (required) * @return SuccessResponse * @throws ApiException if fails to make API call * @http.response.details * <table summary="Response Details" border="1"> * <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr> * <tr><td> 200 </td><td> OK </td><td> - </td></tr> * <tr><td> 0 </td><td> error </td><td> - </td></tr> * </table> * * @see <a href="https://docs.manticoresearch.com/latest/html/http_reference/json_insert.html">Create a new document in an index Documentation</a> */ public SuccessResponse Insert(InsertDocumentRequest insertDocumentRequest) { return(InsertWithHttpInfo(insertDocumentRequest).GetData()); }