elasticsearch - 弹性搜索嵌套对象自动完成
问题描述
我正在尝试将自动完成功能添加到我在弹性搜索中创建的嵌套对象中。
我设置的映射设置:
"mappings": {
"doc": {
"object": {
"type": "nested",
"properties": {
"author": {
"type": "text",
"analyzer": "hebrew"
},
"content": {
"type": "text",
"analyzer": "hebrew"
},
"title": {
"type": "text",
"analyzer": "hebrew"
},
"suggest" : { "type": "completion"}
}
}
}
}
我正在使用嵌套对象,因为我还使用 fscrawler 将 json 文档添加到索引中。
我使用以下查询:
{
"suggest": {
"suggester" : {
"prefix" : "test",
"completion" : {
"field" : "object.suggest"
}
}
}
}
但问题是,无论我输入什么,我都没有得到任何结果。
我是否正确设置了映射?还是查询错误?
解决方案
最后对我有用的是为我想使用自动建议的每个对象字段使用建议子字段,例如,如果我想对字段“作者”和“标题”使用自动建议,那么我会使用:
"mappings": {
"doc": {
"object": {
"type": "nested",
"properties": {
"author": {
"type": "text",
"analyzer": "hebrew",
"fields": {
"exact": {
"type": "text",
"analyzer": "hebrew_exact"
},
"suggest": {
"type": "completion",
"analyzer": "simple",
"preserve_separators": false,
"preserve_position_increments": true,
"max_input_length": 50
}
}
},
"content": {
"type": "text",
"analyzer": "hebrew_exact"
},
"title": {
"type": "text",
"analyzer": "hebrew",
"fields": {
"exact": {
"type": "text",
"analyzer": "hebrew_exact"
},
"suggest": {
"type": "completion",
"analyzer": "simple",
"preserve_separators": false,
"preserve_position_increments": true,
"max_input_length": 50
}
}
}
}
}
}
要使用它,我会使用文档中的建议器搜索字段:“object.title.suggest”。
推荐阅读
- c - 即使条件为假,为什么我的循环仍在运行?
- testing - 如何捕获请求标头部分中显示的 Load Runner 中的动态值?
- php - 如何在没有 SQL 的情况下允许一次加载页面
- android - 如何从 android studio 中的 recyclerview 获取选中复选框的 id?
- shake-build-system - 可以摇动生成graphviz格式的依赖图吗?
- html - 如何将屏幕截图图像适合 iPhone 框架显示
- kubernetes - 将标志更改为在 Docker for Mac 中运行的 kubernetes api-server
- c - 为什么 Linux 的 pty 驱动程序要用 NUL 代替 VEOF?
- php - 在 PHP 中用 OR 比较两个字符串
- matlab - 如何在我的数据集上应用不归一化的 k-means 和带归一化的 k-means?