我试图用elasticsearch/NEST索引pdf文档。ElasticSearch&附件类型(NEST C#)
该文件已建立索引,但搜索结果返回0次匹配。
我需要的搜索结果只返回文档ID和高亮结果
(不以base64内容)
下面是代码:
在这里我要感谢所有帮助,
感谢,
class Program
{
static void Main(string[] args)
{
// create es client
string index = "myindex";
var settings = new ConnectionSettings("localhost", 9200)
.SetDefaultIndex(index);
var es = new ElasticClient(settings);
// delete index if any
es.DeleteIndex(index);
// index document
string path = "test.pdf";
var doc = new Document()
{
Id = 1,
Title = "test",
Content = Convert.ToBase64String(File.ReadAllBytes(path))
};
var parameters = new IndexParameters() { Refresh = true };
if (es.Index<Document>(doc, parameters).OK)
{
// search in document
string query = "semantic"; // test.pdf contains the string "semantic"
var result = es.Search<Document>(s => s
.Query(q =>
q.QueryString(qs => qs
.Query(query)
)
)
.Highlight(h => h
.PreTags("<b>")
.PostTags("</b>")
.OnFields(
f => f
.OnField(e => e.Content)
.PreTags("<em>")
.PostTags("</em>")
)
)
);
if (result.Hits.Total == 0)
{
}
}
}
}
[ElasticType(
Name = "document",
SearchAnalyzer = "standard",
IndexAnalyzer = "standard"
)]
public class Document
{
public int Id { get; set; }
[ElasticProperty(Store = true)]
public string Title { get; set; }
[ElasticProperty(Type = FieldType.attachment,
TermVector = TermVectorOption.with_positions_offsets)]
public string Content { get; set; }
}
此外,搜索证实,映射器,附件插件安装并加载(使用es.yml:plugin.mandatory:映射器-attachments)。尽管如此,我的pdf中没有包含任何词语。我已经搜索了这个问题的答案(stackoverflow和其他人),只有卷曲的例子,没有使用C#/ NEST的使用示例。 (只是一个注释:当搜索document.title('test.pdf')时,我确实收到了文档,但是在搜索'test'时没有命中。 – 2013-02-09 20:54:23
只是为了让你知道我打算为这个明天创建集成测试并回答这个问题。我无法早日回答。 – 2013-02-13 12:19:17
对此问题的任何更新? – slimflem 2013-09-07 19:40:12