一、创建索引和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