正如标题已经显示的那样,我正在尝试索引MS Word文档,并在其中进行全文搜索。
我见过几个例子,但我不知道我在做什么不对。
有关守则:
[ElasticsearchType(Name = "AttachmentDocuments")]
public class Attachment
{
[String(Name = "_content")]
public string Content { get; set; }
[String(Name = "_content_type")]
public string ContentType { get; set; }
[String(Name = "_name")]
public string Name { get; set; }
public Attachment(Task<File> file)
{
Content = file.Result.FileContent;
ContentType = file.Result.FileType;
Name = file.Result.FileName;
}
}上面的"Content“属性在构造函数中设置为"file.Result.FileContent”。"Content“属性是一个base64字符串。
public class Document
{
[Number(Name = "Id")]
public int Id { get; set; }
[Attachment]
public Attachment File { get; set; }
public String Title { get; set; }
}下面是将文档索引到elasticsearch数据库的方法。
public void IndexDocument(Attachment attachmentDocument)
{
// Create the index if it does not already exist
var indexExists = _client.IndexExists(new IndexExistsRequest(ElasticsearchIndexName));
if (!indexExists.Exists)
{
var indexDescriptor =
new CreateIndexDescriptor(new IndexName {Name = ElasticsearchIndexName}).Mappings(
ms => ms.Map<Document>(m => m.AutoMap()));
_client.CreateIndex(indexDescriptor);
}
var doc = new Document()
{
Id = 1,
Title = "Test",
File = attachmentDocument
};
_client.Index(doc);
}根据上面的代码,文档会被索引到正确的索引中(从Elasticsearch主机-Searchly获取的屏幕):
文件中的内容是:"VCXCVXCVXCVXCVXVXCVXCV“,通过以下查询,我得到了零点击:
QueryContainer queryContainer = null;
queryContainer |= new MatchQuery()
{
Field = "file",
Query = "VCXCVXCVXCVXCVXVXCVXCV"
};
var searchResult =
await _client.LowLevel.SearchAsync<string>(ApplicationsIndexName, "document", new SearchRequest()
{
From = 0,
Size = 10,
Query = queryContainer,
Aggregations = GetAggregations()
});如果有人能暗示我做错了什么,或者应该调查一下,我会觉得很危险。
在我的Elasticsearch数据库中提供映射的屏幕截图:
发布于 2016-12-12 12:06:17
因为你引用了错误的字段。字段应该是file.content
queryContainer |= new MatchQuery()
{
Field = "file.content",
Query = "VCXCVXCVXCVXCVXVXCVXCV"
};https://stackoverflow.com/questions/41100049
复制相似问题