elasticsearch - 从搜索中排除某些字段 - Elasticsearch
问题描述
我已经为每个超过 100 个字段的文档编制了索引,每个字段都使用 Edge gram 标记器进行分析以支持自动建议。我确实需要搜索所有字段的自由文本搜索。当我尝试这样做时,搜索也会发生具有自动完成分析的字段(例如 Data.autocomplete_analyzed)。我必须通过仅搜索使用“文本”类型(例如数据)分析的字段来限制这一点。1.索引时间2.查询时间有没有办法做到这一点。映射文件:
"mappings": {
"_doc": {
"properties": {
"Data": {
"type": "text",
"fields": {
"autocomplete_analyzed": {
"type": "text",
"analyzer": "autocomplete"
},
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
搜索查询:
{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "aim",
"type": "phrase",
"slop": "2",
"fields": []
}
},
{
"multi_match": {
"query": "aim",
"fuzziness": "1",
"fields": []
}
}
],
"minimum_should_match": 1
}
解决方案
在查询时,您可以使用源过滤来选择您想要的字段。
GET /_search
{
"_source": [ "obj1.*", "obj2.*" ],
"query" : {
"term" : { "user" : "kimchy" }
}
}
如果您使用 query_string 进行搜索,您可以使用字段
GET /_search
{
"query": {
"query_string": {
"query": "this AND that OR thus",
"fields": [
"docfilename",
"filepath",
"singlewordfield"
]
}
}
}
推荐阅读
- generics - 为数据绑定 ObservableField 创建 TypeAdapterFactory
- c# - Selenium Webdriver InternetExplorer 随机 HTTP 请求失败
- php - laravel updated_at 默认为 null 并更新当前时间戳迁移
- python - ConfigParser - 将整个部分作为 dict 获取并设置值
- python - 音乐播放器 - 跳过歌曲+暂停等问题
- r - dplyr 条件匹配和计数
- bdd - 空手道:查询参数值正在被编码
- css - 如何导出在 Firefox 开发工具中所做的 CSS 修改?
- database - 离线时发布(React-Native)
- division - 如何将两个整数相除而不得到0?