gpt4 book ai didi

elasticsearch - Elasticsearch-尝试索引MS Word附件并在其中进行全文本搜索

转载 作者:行者123 更新时间:2023-12-03 01:50:03 24 4
gpt4 key购买 nike

正如标题已表明的那样,我正在尝试为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”。 “内容”属性是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):

Searchly Screenshot

该文件中的内容是:“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数据库中的映射的屏幕截图:

Elasticsearch - Mapping

最佳答案

因为您指的是错误的字段。字段应为file.content

 queryContainer |= new MatchQuery()
{
Field = "file.content",
Query = "VCXCVXCVXCVXCVXVXCVXCV"
};

关于elasticsearch - Elasticsearch-尝试索引MS Word附件并在其中进行全文本搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41100049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com