我的记录可以为单个文本字段提供多种翻译,例如:
{
"type": "movie",
"title": {
"en": "Dark Knight",
"de": "Der dunkle Ritter"
}
}
为了表示这些记录,我创建了以下索引:
{
"mappings": {
"_doc": {
"properties": {
"type": {
"type": "text",
"analyzer": "english"
},
"title": {
"type": "nested",
"properties": {
"de": {
"type": "text",
"analyzer": "german"
},
"en": {
"type": "text",
"analyzer": "english"
}
}
}
}
}
}
}
但是当我尝试使用multi_map
查询时,它不会返回预期的结果。此查询查找记录(按顶级type
字段搜索):
{
"query": {
"multi_match" : {
"query" : "movie"
}
}
}
但是这个查询没有(按嵌套title.en
字段搜索):
{
"query": {
"multi_match" : {
"query": "dark"
}
}
}
这令人惊讶,因为如果我获得该title.en
字段的术语向量,似乎该记录已被正确索引:
GET /test_with_lang/_doc/1/_termvectors?pretty=true&fields=*
{
"_index": "test_with_lang",
"_type": "_doc",
"_id": "1",
"_version": 1,
"found": true,
"took": 1,
"term_vectors": {
"title.en": {
"field_statistics": {
"sum_doc_freq": 2,
"doc_count": 1,
"sum_ttf": 2
},
"terms": {
"dark": {
"term_freq": 1,
"tokens": [
{
"position": 0,
"start_offset": 0,
"end_offset": 4
}
]
},
"knight": {
"term_freq": 1,
"tokens": [
{
"position": 1,
"start_offset": 5,
"end_offset": 11
}
]
}
}
}
}
}
查询似乎也使用了正确的字段,并且应该匹配其中一个标记:
Request:
GET /test_with_lang/_doc/1/_explain
{
"query": {
"multi_match" : {
"query": "dark"
}
}
}
Reply:
{
"_index": "test_with_lang",
"_type": "_doc",
"_id": "1",
"matched": false,
"explanation": {
"value": 0.0,
"description": "Failure to meet condition(s) of required/prohibited clause(s)",
"details": [
{
"value": 0.0,
"description": "no match on required clause ((type:dark | title.en:dark | title.de:dark))",
"details": [
{
"value": 0.0,
"description": "No matching clause",
"details": []
}
]
},
...
]
}
]
}
}
请注意,它正在dark
字段title.en
( no match on required clause ((type:dark | title.en:dark | title.de:dark))
) 中查找令牌。
我正在使用 Elasticsearch 6.2.1
似乎该查询应该有效。我错过了什么吗?