我是elasticsearch的新手,我尝试使用string
和array of strings
字段创建多字段索引。对于string
字段,它们都工作得很好但是当我在数组中尝试获得一些结果时,它会返回一个空字段。
我的数据:
{
"string_field_one": "one",
"string_field_two": "two",
"array_of_strings_field": [
"2010", "2011", "2012", "2013"
]
}
映射:
{
"string_field_one" : {
"type" : "string",
"analyzer": "snowball",
"copy_to": "group"
},
"string_field_two" : {
"type" : "string",
"analyzer": "snowball",
"copy_to": "group"
},
"array_of_strings_field" : {
"type" : "string",
"analyzer": "keyword",
"copy_to": "group"
}
"group" : {
"type": "multi_field"
}
}
搜索:
"body": {
"query": {
"multi_match": {
"query": "one two 2010",
type: "cross_fields",
operator: "and",
fields: [
"string_field_one",
"string_field_two",
"array_of_strings_field",
"group"
]
}
}
}
期待:
one
,two
或2010
搜索会返回结果one two
搜索应返回结果one two 2010
搜索应返回结果one two 2008
搜索不应返回结果我缺少什么?
答案 0 :(得分:0)
Cross_fields具有约束条件,所有字段应具有相同的search analyzer,或者所有查询字词应出现在具有相同搜索分析器的字段中。这不是这种情况。 在上述情况下,您需要使用query_string:
示例:
"body": {
"query": {
"query_string": {
"query": "one two 2010",
"default_operator": "AND",
"fields": [
"string_field_one",
"string_field_two",
"array_of_strings_field",
"group"
]
}
}
}