使用德语的简单 Elasticsearch PDF 文本搜索
Simple Elasticsearch PDF Text Search using german language
我可以 handle/extract 我的 PDF 文件中的文本,我不太清楚我是否以正确的方式将我的内容存储在 Elasticsearch 中。
我的 PDF 文本大部分是德语 - 带有“ö”、“ä”等字母
为了存储内容的每个字符,我 "escape" 必要的字符并将它们正确编码为 JSON 以便我可以存储它们。
例如:
我想存储以下 (PDF) 文本:
Öffentliche Verkehrsmittel. TestPath: C:\Windows\explorer.exe
我像这样转换并上传到 Elasticsearch:
{"text":"\u00D6ffentliche Verkehrsmittel. TestPath: C:\\Windows\\explorer.exe"}
我的问题是:这样存储文件的方式正确吗?
Elasticsearch 提供了广泛的 inbuilt language-specific analyzer,如果您要创建文本字段并存储数据,默认情况下会使用标准分析器。你改变如下:
{
"mappings": {
"properties": {
"title.german" :{
"type" :"text",
"analyzer" : "german"
}
}
}
}
您还可以使用 analyze API
检查语言分析器在您的案例德语中生成的标记
{
"text" : "Öffentliche",
"analyzer" : "german"
}
并生成token
{
"tokens": [
{
"token": "offentlich",
"start_offset": 0,
"end_offset": 11,
"type": "<ALPHANUM>",
"position": 0
}
]
}
Ö
的代币
{
"text" : "Ö",
"analyzer" : "german"
}
{
"tokens": [
{
"token": "o",
"start_offset": 0,
"end_offset": 1,
"type": "<ALPHANUM>",
"position": 0
}
]
}
注意:- 它将它转换为纯文本,所以现在无论您搜索 Ö
还是 ö
它都会出现在搜索结果中,因为同一个分析器是如果您使用匹配查询,则在查询时应用。
我可以 handle/extract 我的 PDF 文件中的文本,我不太清楚我是否以正确的方式将我的内容存储在 Elasticsearch 中。
我的 PDF 文本大部分是德语 - 带有“ö”、“ä”等字母
为了存储内容的每个字符,我 "escape" 必要的字符并将它们正确编码为 JSON 以便我可以存储它们。
例如:
我想存储以下 (PDF) 文本:
Öffentliche Verkehrsmittel. TestPath: C:\Windows\explorer.exe
我像这样转换并上传到 Elasticsearch:
{"text":"\u00D6ffentliche Verkehrsmittel. TestPath: C:\\Windows\\explorer.exe"}
我的问题是:这样存储文件的方式正确吗?
Elasticsearch 提供了广泛的 inbuilt language-specific analyzer,如果您要创建文本字段并存储数据,默认情况下会使用标准分析器。你改变如下:
{
"mappings": {
"properties": {
"title.german" :{
"type" :"text",
"analyzer" : "german"
}
}
}
}
您还可以使用 analyze API
检查语言分析器在您的案例德语中生成的标记{
"text" : "Öffentliche",
"analyzer" : "german"
}
并生成token
{
"tokens": [
{
"token": "offentlich",
"start_offset": 0,
"end_offset": 11,
"type": "<ALPHANUM>",
"position": 0
}
]
}
Ö
{
"text" : "Ö",
"analyzer" : "german"
}
{
"tokens": [
{
"token": "o",
"start_offset": 0,
"end_offset": 1,
"type": "<ALPHANUM>",
"position": 0
}
]
}
注意:- 它将它转换为纯文本,所以现在无论您搜索 Ö
还是 ö
它都会出现在搜索结果中,因为同一个分析器是如果您使用匹配查询,则在查询时应用。