NEST 字符串sort

时间:2019-09-21
本文章向大家介绍NEST 字符串sort,主要包括NEST 字符串sort使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

text字符串sort会先分词。可先建立filed字段。并设置为keyword

mapping

        public void Mapping()
        {
            var response = client.IndexExists("employee");
            if (!response.Exists)
            {
                client.CreateIndex("employee");
            }
            client.Map<employee>(m => m.Properties(p => p.Text(t => t.Name("last_name").Fielddata().Analyzer("english").Fields(f=>f.Keyword(k=>k.Name("raw"))))).AutoMap());
        }

  

sort

        public void Sort()
        {
           // client.Search<employee>(s => s.Query(q => q.Bool(b => b.Filter(f => f.Term(t => t.Field("last_name").Value("test01"))))).Pretty());
            client.Search<employee>(s =>
                s.Query(q =>
                    q.ConstantScore(c =>
                        c.Filter(f =>
                            f.Term(t =>
                                t.Field("age").Value("26")
                                ))))
                    .Sort(so => 
                    so.Descending("last_name")
                     )
                    .Pretty());

        }

原文地址:https://www.cnblogs.com/chenyishi/p/11561482.html