弹性搜索 - 更喜欢此查询返回空结果

Elastic search - More Like this query returning empty result

我正在使用 Elastic search 创建某种标签引擎。我正在插入文档,但无法检索它。我重现问题的步骤:

1) 创建索引:

PUT index
{
"mappings": {
    "taggeable" : {
        "_all" : {"enabled" : false},
        "properties" : {
            "id" : {
                "type" : "string",
                "index" : "no"
            },
            "tags" : {
                  "type" : "text"
            }
            }
        }
    }
}

2) 插入文档:

POST index/taggeable
{
"id" : "1",
"tags" : "tag1 tag2"
}

3) 使用 More like This 查询:

GET index/_search
{
"query": {
    "more_like_this" : {
        "fields" : ["tags"],
        "like" : ["tag1"],
        "min_term_freq" : 1
    }
}
}

但我收到了:

{
"_shards": {
    "failed": 0, 
    "skipped": 0, 
    "successful": 5, 
    "total": 5
}, 
"hits": {
    "hits": [], 
    "max_score": null, 
    "total": 0
}, 
"timed_out": false, 
"took": 1
}

有人知道我做错了什么吗?我应该取回我插入的文档。

您设置了参数

min_term_freq

The minimum term frequency below which the terms will be ignored from the input document. Defaults to 2.

这很好,否则默认为2。还有一个参数

min_doc_freq

The minimum document frequency below which the terms will be ignored from the input document. Defaults to 5.

在您的情况下,如果您只有 1 个文档,这将被忽略,因此您需要添加更多文档,或者将参数 min_doc_freq 指定为 1