node.js - 是否可以在 elasticsearch-js 中使用高亮显示?
问题描述
我正在开发以下代码片段:
app.get('/search', function (req, res){
let body = {
size: 200,
from: 0,
highlight: {
pre_tags : ["<tag1>"],
post_tags : ["</tag1>"],
fields: {
"_content" : {}
}
}
}
client.search({index:'juridico', q: req.query['q'], body: body})
.then(results => {
console.log(results);
res.send(results.hits.hits);
})
.catch(err=>{
console.log(err)
res.send([]);
});
})
但是当我在 body 上传递 highlight 参数时,我没有得到它的响应。
解决方案
我不得不像这样解决身体周围的领域:
let body = {
highlight: {
require_field_match: false,
fields: {
'*': {
pre_tags: ['<span>'],
post_tags: ['</span>']
}
}
}
}
我使用'*'
here 作为通配符来搜索所有字段。我相信如果您想搜索具有相同前置/后置修复的许多字段,您也可以使用它。希望这对你有用!
推荐阅读
- sql-server - 数据没有存储在数据库中?我正在使用 python 和 pyodbc
- python - Python append 与 concat 在“For Loop”中具有多个文件
- swift - 将 UnsafeMutableRawPointer 作为函数参数传递
- r - 如何在 R 中保留 read.table 的空格字符?
- python - 如何从给定城市的给定日期和时间获取 unix 纪元时间戳(以秒为单位)?
- c# - 实体对象不能被多个 IEntityChangeTracker 实例引用。从 POST 上的视图更新记录时触发
- firebase - Flutter firebase_admob 无法在 iOS 生产中加载广告
- javascript - Gremlin (Neptune) 有些复杂的查询不显示边缘属性
- ios - 如何使用 Swift 从 Mapbox 获取纬度/经度坐标的地表高程?
- ios - 更改 AVAudioSession 的模式时,AVRoutePickerView 显示不正确的输出设备信息