我正在尝试让Elasticsearch索引.txt文件,以便我可以搜索内容.我已经取得了一些进展,但在搜索部分没有运气.
这是我的映射:
mappings: {
file: {
properties: {
allow_token_share: {
type: string
},
file: {
type: string
},
deny_token_document: {
type: string
},
_name: {
type: string
},
_content_type: {
type: string
},
type: {
type: string
},
uri: {
type: string
},
deny_token_share: {
type: string
},
allow_token_document: {
type: string
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我索引的文档:
{
_index: f_drive,
_type: file,
_id: file:/C:/Users/ttobinca.EPIC/Documents/Dev/Epicsearch/TestDocs/Test.txt,
_version: 1,
_score: 1,
_source: {
uri: C:\Users\ttobinca.EPIC\Documents\Dev\Epicsearch\TestDocs\Test.txt,
allow_token_document: __nosecurity__,
deny_token_document: __nosecurity__,
allow_token_share: __nosecurity__,
deny_token_share: __nosecurity__,
type: attachment,
_content_type: text/plain,
_name: Test.txt,
file: SSBsaWtlIGhhbWJ1cmdlcnMgYW5kIGhvdGRvZ3MsIGJ1dCBtb3N0bHkgY2hvY29sYXRlLg0KDQpIZWxsbyB3b3JsZC4=
}
}
Run Code Online (Sandbox Code Playgroud)
该文件的内容是:
我喜欢汉堡包和热狗,但主要是巧克力.
你好,世界.
第一个问题是,这个文件索引正确吗?如果是这样,我该如何搜索本文档的内容?运行此查询不会返回任何结果:
{
"query": {
"query_string": {
"query": "hamburgers"
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这会返回文档.
{
"query": {
"query_string": {
"query": "SSBsaWtlIGhhbWJ1cmdlcnMgYW5kIGhvdGRvZ3MsIGJ1dCBtb3N0bHkgY2hvY29sYXRlLg0KDQpIZWxsbyB3b3JsZC4="
}
}
}
Run Code Online (Sandbox Code Playgroud)
默认情况下不支持索引二进制内容.你必须安装并使用mapper-attachment插件.这将启用attachment您可以在映射中使用的自定义类型.这样,elasticsearch将使用apache tika从二进制文件中提取文本并将其作为文本索引.只有在那之后,您才能通过文本查询获得结果.
请考虑使用附件插件,您正在弹性搜索节点内执行服务器端二进制内容的解析,这可能不是一个好主意,因为您必须为该节点保留该节点上的电源和内存处理而不是使用它来索引和搜索文本.
| 归档时间: |
|
| 查看次数: |
4610 次 |
| 最近记录: |