elasticsearch - Elasticsearch NEST突出显示附件内容

标签 elasticsearch nest elasticsearch-plugin elasticsearch-net

在Elasticsearch 5.6.3中,我安装了摄取附件插件。我正在尝试将附件内容中的术语 vector 属性设置为 WithPositionOffsets 我应该在哪里设置此属性以在搜索中查看高限制的结果?

文件POCO如下:

public class Document
{
    public int Id { get; set; }
    public string Path { get; set; }
    public string Content { get; set; }
    public Attachment Attachment { get; set; }
}

这是带有映射的CreateIndex函数。
var indexResponse = client.CreateIndex(documentsIndex, c => c
                                      .Settings(s => s
                                        .Analysis(a => a
                                          .Analyzers(ad => ad
                                            .Custom("windows_path_hierarchy_analyzer", ca => ca
                                              .Tokenizer("windows_path_hierarchy_tokenizer")
                                            )
                                          )
                                          .Tokenizers(t => t
                                            .PathHierarchy("windows_path_hierarchy_tokenizer", ph => ph
                                              .Delimiter('\\')
                                            )
                                          )
                                        )
                                      )
                                      .Mappings(m => m
                                        .Map<Document>(mp => mp
                                          .AutoMap()
                                          .AllField(all => all
                                            .Enabled(false)
                                          )
                                          .Properties(ps => ps
                                            .Text(s => s
                                              .Name(n => n.Path)
                                              .Analyzer("windows_path_hierarchy_analyzer")
                                            )
                                            .Attachment(at => at.
                                            Name(n => n.Attachment.Content)
                                            .FileField(ff => ff
                                                .Name("Content")
                                                .TermVector(TermVectorOption.WithPositionsOffsets)
                                                .Store()))
                                            //.Text(s => s
                                            //  .Name(n => n.Attachment.Content)
                                            //  .TermVector(TermVectorOption.WithPositionsOffsets)
                                            //  .Store(true)
                                            //)
                                            .Object<Attachment>(a => a
                                              .Name(n => n.Attachment)
                                              .AutoMap()
                                            )
                                          )
                                        )
                                      )
                                    );

进入.Mappings部分,我使用FileField设置termvector和store属性。但是结果如下:
{
"documents": {
    "mappings": {
        "document": {
            "_all": {
                "enabled": false
            },
            "properties": {
                "attachment": {
                    "properties": {
                        "author": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "content": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "content_length": {
                            "type": "long"
                        },
                        "content_type": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "date": {
                            "type": "date"
                        },
                        "detect_language": {
                            "type": "boolean"
                        },
                        "indexed_chars": {
                            "type": "long"
                        },
                        "keywords": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "language": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "name": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "title": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        }
                    }
                },
                "content": {
                    "type": "attachment",
                    "fields": {
                        "content": {
                            "type": "text",
                            "store": true,
                            "term_vector": "with_positions_offsets"
                        },
                        "author": {
                            "type": "text"
                        },
                        "title": {
                            "type": "text"
                        },
                        "name": {
                            "type": "text"
                        },
                        "date": {
                            "type": "date"
                        },
                        "keywords": {
                            "type": "text"
                        },
                        "content_type": {
                            "type": "text"
                        },
                        "content_length": {
                            "type": "integer"
                        },
                        "language": {
                            "type": "text"
                        }
                    }
                },
                "id": {
                    "type": "integer"
                },
                "path": {
                    "type": "text",
                    "analyzer": "windows_path_hierarchy_analyzer"
                }
            }
        }
    }
}

}

因此,我在查询结果中看不到Highlight属性。我应该怎么做?

最佳答案

要使用摄取附件插件,请勿将Attachment属性映射为attachment数据类型;此映射适用于在5.x中已弃用并在6.x中删除的mapper-attachment插件。

I wrote a blog post about using ingest-attachment with .NET,其中包括Attachment的示例映射;本质上,将其映射为object数据类型,并将其上的Content属性映射为应用了text.TermVector(TermVectorOption.WithPositionsOffsets)数据类型。您需要先在索引中创建此映射,然后再将所有带有附件的文档编入索引。

关于elasticsearch - Elasticsearch NEST突出显示附件内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47031334/

相关文章:

elasticsearch - 有什么办法(插件)将kibana查询语法解析为elasticsearch api主体?

c# - Elasticsearch搜索不区分大小写的字段的确切值

用于对文档进行分类的 Elasticsearch 插件

elasticsearch - 重新索引,同时将特定字段(在旧索引中存在)的字符串值转换为数字字段值(在新索引中)

search - 通过查询字符串搜索在特定字段上不起作用的空间

Elasticsearch |使用包含术语和术语的列表查询文档不起作用

Elasticsearch 聚合之聚合

c# - ElasticSearch NEST 7.x 将项目附加到现有文档对象数组属性

c# - ElasticSearch 索引映射和通配符

Elasticsearch 2.0 插件安装信息