我相信你可以实现你想要的
copy_to
. 我来告诉你为什么不需要它。
如何在同一字段上进行全文和精确匹配查询?
这可以用
fields
映射属性。基本上,使用以下映射:
PUT producten_prd_5_test_new
{
"aliases": {},
"mappings": {
"boek": {
"properties": {
"hoofdtitel": {
"type": "text", <== analysing for full text search
"fields": {
"keyword": {
"type": "keyword" <== analysing for exact match
},
"suggest": {
"type": "completion", <== analysing for suggest
"analyzer": "simple",
"preserve_separators": false,
"preserve_position_increments": true,
"max_input_length": 50
}
}
}
}
}
}
}
您将告诉ElasticSearch对同一字段进行三次索引:一次用于全文搜索,一次用于精确匹配,一次用于建议。
准确的搜索可以通过
term
这样的查询:
GET producten_prd_5_test_new/_search
{
"query": {
"term": {
"hoofdtitel.keyword": "The Nature of the Firm in the Oil Industry"
}
}
}
为什么这个领域
exact_hoofdtitel
没有出现在返回的文档中?
因为
抄本
不更改源:
原始源字段将不会被修改以显示复制的
价值观。
它工作得很像
_all
字段,允许您在一个虚字段中合并多个字段的值,并以特殊的方式对其进行分析。
这样做有意义吗
抄本
对
index: false
字段?
用
索引:假
该字段将不会被分析,也不会被搜索(如在您的示例中,该字段
exact_hoofdtitel.keyword
)
如果要对该字段进行关键字聚合,则这样做仍然有意义:
GET producten_prd_5_test/_search
{
"aggs": {
"by copy to": {
"terms": {
"field": "exact_hoofdtitel.keyword"
}
}
}
}
这将返回如下内容:
{
"aggregations": {
"by copy to": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "The Nature of the Firm in the Oil Industry",
"doc_count": 1
}
]
}
}
}
希望有帮助!