我想在文档中添加一个字段,该字段应该是可搜索的,但是当我们执行get / search时,它不应出现在_source下。
我已经尝试过索引和存储选项,但无法通过它实现。
它更像是_all或copy_to,但在我看来,该值是由我提供的(不是从文档的其他字段收集的)。
我正在寻找可以实现以下情况的映射。
当我放置文件时:
PUT my_index/_doc/1
{
"title": "Some short title",
"date": "2015-01-01",
"content": "A very long content field..."
}
并搜索
GET my_index / _search
输出应该是
{
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"title" : "Some short title",
"date" : "2015-01-01"
}
}
]
}
}
当我做下面的搜索时
GET my_index/_search
{
"query": {
"query_string": {
"default_field": "content",
"query": "long content"
}
}
}
它应该导致我
"hits" : {
"total" : 1,
"max_score" : 0.5753642,
"hits" : [
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.5753642,
"_source" : {
"title" : "Some short title",
"date" : "2015-01-01"
}
}
]
}
最佳答案
只需使用source filtering排除content
字段即可:
GET my_index/_search
{
"_source": {
"excludes": [ "content" ]
},
"query": {
"query_string": {
"default_field": "content",
"query": "long content"
}
}
}
关于elasticsearch - 有什么方法可以在文档中添加该字段,但对_source隐藏该字段,还应该对文档进行分析和搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55339289/