弹性搜索映射器附件,索引时抛出嵌套错误
我最近开始使用弹性搜索,我正在尝试使用mapper附件插件为pdf文档编制索引,在编制索引时遇到错误值不能为null参数名称:index,是否有人可以帮助修复此 以下是索引代码:弹性搜索映射器附件,索引时抛出嵌套错误,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我最近开始使用弹性搜索,我正在尝试使用mapper附件插件为pdf文档编制索引,在编制索引时遇到错误值不能为null参数名称:index,是否有人可以帮助修复此 以下是索引代码: static void Main(string[] args) { var connectionSettings = new ConnectionSettings(new Uri("http://localhost:9200/")); var elasticClient
static void Main(string[] args)
{
var connectionSettings = new ConnectionSettings(new Uri("http://localhost:9200/"));
var elasticClient = new ElasticClient(connectionSettings);
elasticClient.CreateIndex("pdf-index", c => c.AddMapping<Document>(m => m.MapFromAttributes()));
var attachment = new Attachment
{
Content = Convert.ToBase64String(File.ReadAllBytes("test.pdf")),
ContentType = "application/pdf",
Name = "test.pdf"
};
var doc = new Document()
{
Id = 1,
Title = "test",
File = attachment
};
elasticClient.Index(doc);
}
public class Attachment
{
[ElasticProperty(Name = "_content")]
public string Content { get; set; }
[ElasticProperty(Name = "_content_type")]
public string ContentType { get; set; }
[ElasticProperty(Name = "_name")]
public string Name { get; set; }
}
public class Document
{
public int Id { get; set; }
public string Title { get; set; }
[ElasticProperty(Type = FieldType.Attachment, TermVector = TermVectorOption.WithPositionsOffsets, Store = true)]
public Attachment File { get; set; }
}
我猜你忘了在弹性搜索连接设置中添加默认索引
var uri = new Uri("http://localhost:9200/");
var connectionSettings = new ConnectionSettings(uri, defaultIndex: "my-application");
var elasticClient=新的ElasticClientconnectionSettings
更多信息请点击这里
当然,默认索引是可选的。然后在索引文档时必须指定索引。
e、 g
client.Index(doc, i => i
.Index(index)
.Type(type)
);