我需要将弹性搜索文档的字段声明为NOT ANALYZED,因为我想使用通配符查询来匹配它。
如何使用NEST 2.4.5完成此操作?
我已经尝试了[String(Index = FieldIndexOption.NotAnalyzed)]但似乎它没有工作......
为了在ES上推送文档我使用以下代码来描述ES文档:
public class mydoc
{
private string _md5;
private string _filename;
private string _file_path;
private string _type;
private string _data_json; //<--- this should be NOT ANALYZED
private DateTime _date;
[JsonConstructor]
public mydoc(string md5, string filename, string file_path, string type, string data_json, DateTime date)
{
this._md5 = md5;
this._filename = filename;
this._file_path = file_path;
this._type = type;
this._data_json = data_json;
this._date = date;
}
}
/* GETTER AND SETTER HERE */
这是为了将其推入ES:
public mydocPutInfo(string md5, string filename, string base_64 , string type, string data_json)
{
mydoc pfd = new mydoc(md5, filename, base_64, type, metadata_json, DateTime.Now);
string json = SerializeInfo(pfd);
var client = ESConnector.GetESClient();
var index = client.Index(pfd, i => i
.Index(EL_MY_INDEX)
.Type(EL_MY_TYPE)
.Id(md5.ToString())
);
return pfd;
}