问题描述
我有一个名为IndexModel类:
I have a class named "IndexModel":
public class IndexModel
{
[ElasticProperty(Index= FieldIndexOption.NotAnalyzed, Store = true)]
public string ModelNumber{ get; set; }
}
下面是我如何设置弹性客户端:
following is how i setup the elastic client:
var uri = new Uri("http://localhost:9200");
var config = new ConnectionSettings(uri);
var client = new ElasticClient(config);
client.Map<IndexModel>(m => m.MapFromAttributes());
我可以看到从响应映射的结果是:
I can see the mapped result from response:
Request {
"indexmodel": {
"properties": {
"modelNumber": {
"type": "string",
"store": true,
"index": "not_analyzed"
},
}
}
}
和我有这种类型的一个索引记录,ModelNumber属性的值为测试-123 ,而下面是我的查询:
and i have one index record for this type, the value of "ModelNumber" property is "test-123", and following is my query:
var result = client.Search<IndexModel>(s => s.Query(new TermQuery() { Field = Property.Path<IndexModel>(it => it.ModelNumber), Value = "test-123"}));
下面是最后的映射要求我得到:
here is the final mapped request i got:
Method: POST,
Url: http://localhost:9200/_search,
Request: {
"query": {
"term": {
"modelNumber": {
"value": "test-123"
}
}
}
}
但我不能得到的结果,如果我改变ModelNumber的价值属性为test123 ,重新建立索引,并通过关键词test123搜索它,那么它的作品,所以我觉得仪仍分析了ModelNumber属性,有人可以帮助我,谢谢。
But i can not get the result, if i change the value of "ModelNumber" property to "test123", re-index it, and search it by keywords "test123", then it's works, so i think the analyzer still analyzed the "ModelNumber" property, can someone help me, thanks.
推荐答案
我有同样的问题,解决的办法是先建立索引然后把映射,并在最后添加数据。
I had the same problem, the solution is first create the index then put the mapping and at last add your data.
类型属性添加到您的模型字段
Add Type Attribute to your model field
[ElasticProperty(OmitNorms = true, Index = FieldIndexOption.NotAnalyzed)]
var node = new Uri("http://192.168.0.56:9200/");
var settings = new ConnectionSettings(node, defaultIndex: "ticket");
var client = new ElasticClient(settings);
var createIndexResult = client.CreateIndex("ticket");
var mapResult = client.Map<TicketElastic>(c => c.MapFromAttributes().IgnoreConflicts().Type("TicketElastic").Indices("ticket"));
这篇关于elasticsearch NEST客户端,用属性和QUOT申请; not_analyzed"当搜索关键词中包含连字符仍然被分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!