protected string GetSearchType(SearchDescriptorBase descriptor, MultiSearchDescriptor multiSearchDescriptor) { if (descriptor._SearchType != null) { switch (descriptor._SearchType.Value) { case SearchTypeOptions.Count: return("count"); case SearchTypeOptions.DfsQueryThenFetch: return("dfs_query_then_fetch"); case SearchTypeOptions.DfsQueryAndFetch: return("dfs_query_and_fetch"); case SearchTypeOptions.QueryThenFetch: return("query_then_fetch"); case SearchTypeOptions.QueryAndFetch: return("query_and_fetch"); case SearchTypeOptions.Scan: return("scan"); } } return(multiSearchDescriptor._QueryString.GetQueryStringValue <string>("search_type")); }
/// <summary> /// _msearch needs a specialized json format in the body /// </summary> public string SerializeMultiSearch(MultiSearchDescriptor multiSearchDescriptor) { var sb = new StringBuilder(); var inferrer = new ElasticInferrer(this._settings); foreach (var operation in multiSearchDescriptor._Operations.Values) { var path = operation.ToPathInfo(this._settings); var op = new { index = path.Index, type = path.Type, search_type = this.GetSearchType(operation, multiSearchDescriptor), preference = operation._Preference, routing = operation._Routing }; var opJson = this.Serialize(op, SerializationFormatting.None).Utf8String(); var action = "{0}\n".F(opJson); sb.Append(action); var searchJson = this.Serialize(operation, SerializationFormatting.None).Utf8String(); sb.Append(searchJson + "\n"); } var json = sb.ToString(); return(json); }
public MultiSearchResponse MultiSearch(MultiSearchDescriptor multiSearchDescriptor) { multiSearchDescriptor.ThrowIfNull("multiSearchDescriptor"); var sb = new StringBuilder(); foreach (var operation in multiSearchDescriptor._Operations.Values) { var indeces = operation._Indices.HasAny() ? string.Join(",", operation._Indices) : null; if (operation._AllIndices) { indeces = "_all"; } var index = indeces ?? multiSearchDescriptor._FixedIndex ?? new IndexNameResolver(this.Settings).GetIndexForType(operation._ClrType); var types = operation._Types.HasAny() ? string.Join(",", operation._Types) : null; var typeName = types ?? multiSearchDescriptor._FixedType ?? new TypeNameResolver().GetTypeNameForType(operation._ClrType); if (operation._AllTypes) { typeName = null; //force empty typename so we'll query all types. } var op = new { index = index, type = typeName, search_type = this.GetSearchType(operation), preference = operation._Preference, routing = operation._Routing }; var opJson = JsonConvert.SerializeObject(op, Formatting.None, IndexSerializationSettings); var action = "{0}\n".F(opJson); sb.Append(action); var searchJson = JsonConvert.SerializeObject(operation, Formatting.None, IndexSerializationSettings); sb.Append(searchJson + "\n"); } var json = sb.ToString(); var path = "_msearch"; if (!multiSearchDescriptor._FixedIndex.IsNullOrEmpty()) { if (!multiSearchDescriptor._FixedType.IsNullOrEmpty()) { path = multiSearchDescriptor._FixedType + "/" + path; } path = multiSearchDescriptor._FixedIndex + "/" + path; } var status = this.Connection.PostSync(path, json); var multiSearchConverter = new MultiSearchConverter(multiSearchDescriptor); var multiSearchResponse = this.ToParsedResponse <MultiSearchResponse>(status, extraConverters: new List <JsonConverter> { multiSearchConverter }); return(multiSearchResponse); }
/// <summary> /// _msearch needs a specialized json format in the body /// </summary> public string SerializeMultiSearch(MultiSearchDescriptor multiSearchDescriptor) { var sb = new StringBuilder(); var inferrer = new ElasticInferrer(this._settings); foreach (var operation in multiSearchDescriptor._Operations.Values) { var indices = inferrer.IndexNames(operation._Indices); if (operation._AllIndices.GetValueOrDefault(false)) { indices = "_all"; } var index = indices ?? inferrer.IndexName(multiSearchDescriptor._Index) ?? inferrer.IndexName(operation._ClrType); var types = inferrer.TypeNames(operation._Types); var typeName = types ?? inferrer.TypeName(multiSearchDescriptor._Type) ?? inferrer.TypeName(operation._ClrType); if (operation._AllTypes.GetValueOrDefault(false)) { typeName = null; //force empty typename so we'll query all types. } var op = new { index = index, type = typeName, search_type = this.GetSearchType(operation, multiSearchDescriptor), preference = operation._Preference, routing = operation._Routing }; var opJson = this.Serialize(op, SerializationFormatting.None).Utf8String(); var action = "{0}\n".F(opJson); sb.Append(action); var searchJson = this.Serialize(operation, SerializationFormatting.None).Utf8String(); sb.Append(searchJson + "\n"); } var json = sb.ToString(); return(json); }
private JsonConverter CreateMultiSearchConverter(MultiSearchDescriptor descriptor) { var multiSearchConverter = new MultiSearchConverter(_connectionSettings, descriptor); return(multiSearchConverter); }
public MultiSearchResponse DeserializeMultiSearchResponse(ConnectionStatus c, MultiSearchDescriptor d) { var multiSearchConverter = new MultiSearchConverter(this._settings, d); var multiSearchResponse = this.DeserializeInternal <MultiSearchResponse>(c, piggyBackJsonConverter: multiSearchConverter); return(multiSearchResponse); }