首页 > 其他 > 详细

Elasticsearch学习笔记之—初次使用ElasticLinqClient

时间:2019-12-25 12:01:35      阅读:152      评论:0      收藏:0      [点我收藏+]

一、创建索引和Mapping(注意一定要指定分词器 analyzer,要不然第三步的查询,就查询不正确(但使用ElasticJsonClient可以),在这个问题上折腾了很久很久直到怀疑人生

PUT person_index
{
  "mappings": {
    "personn": {
      "properties": {
        "id":{
          "type":"integer"
        },
        "name":{
          "type":"text",
                    "analyzer":"standard"
        },
        "address": {
          "type": "text",
                    "analyzer":"standard"
        }
      }
    }
  }
}

二、生成索引下的数据

PUT person_index/personn/1
{
  "id":1,
  "name":"张三",
  "address":"北京海淀区352号"
}

PUT person_index/personn/2
{
  "id":2,
  "name":"李四",
  "address":"天津市滨海新区88号"
}

PUT person_index/personn/3
{
  "id":3,
  "name":"王五张",
  "address":""
}

三、查询代码

            string indexName = "person_index";
            var searchResponse = eSSever.ElasticLinqClient.Search<Personn>(s => s
            .From(0)
            .Size(10).Index(indexName)
            .Query(q => q
                     .Match(m => m
                        .Field(f => f.Name)
                        .Query("")
                     )
                )
            );
            var peoples = searchResponse.Documents;

 

Elasticsearch学习笔记之—初次使用ElasticLinqClient

原文:https://www.cnblogs.com/wjx-blog/p/12095693.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!