es完全匹配和包含查询。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//根据用户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;
}

  

posted @   liskov_design  阅读(686)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示