我是Elasticsearch的新手,正在尝试使用string和array of strings字段创建多字段索引。有了这些string字段,它们都工作得很好,但是当我尝试在数组中获取一些结果时,它返回一个空的数组。
string
array of strings
我的资料:
{ "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
我想念什么?
Cross_fields具有约束,所有字段应具有相同的搜索分析器,或者所有查询项应出现在具有相同搜索分析器的字段中。这里不是这种情况。在上述情况下,您需要使用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" ] } } }