首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elasticsearch -尝试索引MS单词附件&在

Elasticsearch -尝试索引MS单词附件&在
EN

Stack Overflow用户
提问于 2016-12-12 11:40:32
回答 1查看 151关注 0票数 0

正如标题已经显示的那样,我正在尝试索引MS Word文档,并在其中进行全文搜索。

我见过几个例子,但我不知道我在做什么不对。

有关守则:

代码语言:javascript
复制
[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字符串。

代码语言:javascript
复制
public class Document
{
    [Number(Name = "Id")]
    public int Id { get; set; }
    [Attachment]
    public Attachment File { get; set; }
    public String Title { get; set; }
}

下面是将文档索引到elasticsearch数据库的方法。

代码语言:javascript
复制
    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镜头

文件中的内容是:"VCXCVXCVXCVXCVXVXCVXCV“,通过以下查询,我得到了零点击:

代码语言:javascript
复制
        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数据库中提供映射的屏幕截图:

弹性搜索-映射

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-12 12:06:17

因为你引用了错误的字段。字段应该是file.content

代码语言:javascript
复制
 queryContainer |= new MatchQuery()
        {
            Field = "file.content",
            Query = "VCXCVXCVXCVXCVXVXCVXCV"
        };
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41100049

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档