我想使用嵌套的“点”字段作为完成提示的键(使用ElasticSearch 6.4)。效果很好:
PUT music/_doc/1?refresh
{
"suggest.music" : {
"input": [ "Nevermind", "Nirvana" ],
"weight" : 34
}
}
...但是此建议查询不起作用:
POST music/_search?pretty
{
"suggest": {
"song-suggest" : {
"prefix" : "nir",
"completion" : {
"field" : "suggest.music"
}
}
}
}
它说“找不到字段[suggest.music]的映射”。这是我的映射:
{
"music" : {
"aliases" : { },
"mappings" : {
"_doc" : {
"properties" : {
"es_suggest" : {
"type" : "completion",
"analyzer" : "simple",
"preserve_separators" : true,
"preserve_position_increments" : true,
"max_input_length" : 50
},
"suggest" : {
"properties" : {
"music" : {
"properties" : {
"input" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"weight" : {
"type" : "long"
}
}
}
}
},
"title" : {
"type" : "keyword"
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1550842862212",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "Dqr3XQJWTqC5YRvJjEvh5w",
"version" : {
"created" : "6060099"
},
"provided_name" : "music"
}
}
}
}
有什么方法可以查询带有嵌套“点”字段的完成建议?
答案 0 :(得分:1)
您正在尝试从字段suggest.music
(不是完成字段)完成操作。在您的映射中,es_suggest
是完成字段。
如果需要,可以更改映射以在嵌套对象中具有完成字段:
PUT music
{
"aliases" : { },
"mappings" : {
"_doc" : {
"properties" : {
"suggest" : {
"properties" : {
"music" : {
"properties" : {
"input" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
},
"completion": {
"type": "completion",
"analyzer" : "simple",
"preserve_separators" : true,
"preserve_position_increments" : true,
"max_input_length" : 50
}
}
}
}
}
}
},
"title" : {
"type" : "keyword"
}
}
}
}
}
然后,您可以使用该字段进行填写:
POST music/_search
{
"suggest": {
"song-suggest" : {
"prefix" : "nir",
"completion" : {
"field" : "suggest.music.input.completion"
}
}
}
}