public SearchResult Search(string index, string[] type, ElasticQuery elasticQuery) { string jsonstr = JsonSerializer.Get(elasticQuery); string url; if (type == null || type.Length == 0) { url = "/{0}/_search".Fill(index.ToLower()); } else { url = "/{0}/{1}/_search".Fill(index.ToLower(), string.Join(",", type)); } RestResponse result = _provider.Post(url, jsonstr); var hitResult = new SearchResult(url,jsonstr,result.GetBody()); return hitResult; }
public List<string> SearchIds(string index, string[] type, string queryString, string sortString, int from, int size) { Contract.Assert(!string.IsNullOrEmpty(index)); Contract.Assert(!string.IsNullOrEmpty(queryString)); queryString = HttpUtility.UrlEncode(queryString.Trim()); string url = string.Empty; if (type == null || type.Length == 0) { url = "/{0}/_search?q={1}&from={2}&size={3}".Fill(index.ToLower(), queryString, from, size); } else { url = "/{0}/{1}/_search?q={2}&fields=_id&from={3}&size={4}".Fill(index.ToLower(), string.Join(",", type), queryString, from, size); } if (!string.IsNullOrEmpty(sortString)) { url += "&sort=" + sortString; } RestResponse result = _provider.Get(url); var hitResult = new SearchResult(url,result.GetBody()); return hitResult.GetHitIds(); }
/// <summary> /// 搜索index下所有type /// </summary> /// <param name="index"></param> /// <param name="queryString"></param> /// <param name="from"></param> /// <param name="size"></param> /// <returns></returns> public SearchResult Search(string index, string queryString, int from, int size) { Contract.Assert(!string.IsNullOrEmpty(index)); Contract.Assert(!string.IsNullOrEmpty(queryString)); Contract.Assert(from >= 0); Contract.Assert(size > 0); queryString = HttpUtility.UrlEncode(queryString.Trim()); string url = "/{0}/_search?q={1}&from={2}&size={3}".Fill(index.ToLower(), queryString, from, size); RestResponse result = _provider.Get(url); var hitResult = new SearchResult(url,result.GetBody()); return hitResult; }
//TODO,remove this method public SearchResult Search(string url) { RestResponse result = _provider.Get(url); var hitResult = new SearchResult(url, result.GetBody()); return hitResult; }
public SearchResult Search(string index, string[] type, string queryString, int from, int size) { Contract.Assert(!string.IsNullOrEmpty(index)); Contract.Assert(!string.IsNullOrEmpty(queryString)); Contract.Assert(from >= 0); Contract.Assert(size > 0); Contract.Assert(queryString != null, "queryString != null"); queryString = HttpUtility.UrlEncode(queryString.Trim()); string url = string.Empty; if (type == null || type.Length == 0) { url = "/{0}/_search?q={1}&from={2}&size={3}".Fill(index.ToLower(), queryString, from, size); } else { url = "/{0}/{1}/_search?q={2}&from={3}&size={4}".Fill(index.ToLower(), string.Join(",", type), queryString, from, size); } RestResponse result = _provider.Get(url); var hitResult = new SearchResult(url,result.GetBody()); return hitResult; }