es完全匹配和包含查询。
//根据用户id完全匹配 //按照用户输入的字符串以空格分隔开来得到数组arr,并且es中必须包含arr[0,length] public static ISearchResponse<spindex_content_es_model> get_list_search_by_key(string uid, string key, int size = 100) { var query = new SearchDescriptor<spindex_content_es_model>(); query.Query(q => get_sp_index_content_es_query_container(q, uid, key)).From(0).Take(size).Sort(st => st.Descending("createtime")); return ElasticsearchClient.get_client_spindex().Search<spindex_content_es_model>(x => query); } //构造查询器 private static QueryContainer get_sp_index_content_es_query_container(QueryContainerDescriptor<spindex_content_es_model> q, string uid, string key) { var qc = new QueryContainer(); qc &= q.Term(s => s.Field("uid.keyword").Value(uid)); if (!string.IsNullOrEmpty(key)) { string[] arr = key.Split(' '); foreach (var x in arr) { if (string.IsNullOrEmpty(x)) continue; qc &= q.MatchPhrase(s => s.Field(f => f.content).Query(x)); } } return qc; }