gpt4 book ai didi

Elasticsearch 更喜欢这个查询

转载 作者:行者123 更新时间:2023-11-29 02:51:09 24 4
gpt4 key购买 nike

我正在努力思考 more like this 是如何产生的查询有效,我似乎遗漏了一些东西。我阅读了文档,但 ES 文档通常有点……缺乏。

目标是能够按词频限制结果,正如所尝试的那样 here .

所以我设置了一个简单的索引,包括用于调试的术语向量,然后添加了两个简单的文档。

DELETE /test_index

PUT /test_index
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"doc": {
"properties": {
"text": {
"type": "string",
"term_vector": "yes"
}
}
}
}
}

PUT /test_index/doc/1
{
"text": "apple, apple, apple, apple, apple"
}

PUT /test_index/doc/2
{
"text": "apple, apple"
}

当我查看术语向量时,我看到了我所期望的:

GET /test_index/doc/1/_termvector
...
{
"_index": "test_index",
"_type": "doc",
"_id": "1",
"_version": 1,
"found": true,
"term_vectors": {
"text": {
"field_statistics": {
"sum_doc_freq": 2,
"doc_count": 2,
"sum_ttf": 7
},
"terms": {
"apple": {
"term_freq": 5
}
}
}
}
}

GET /test_index/doc/2/_termvector
{
"_index": "test_index",
"_type": "doc",
"_id": "2",
"_version": 1,
"found": true,
"term_vectors": {
"text": {
"field_statistics": {
"sum_doc_freq": 2,
"doc_count": 2,
"sum_ttf": 7
},
"terms": {
"apple": {
"term_freq": 2
}
}
}
}
}

当我使用 "min_term_freq": 1 运行以下查询时,我得到了两个文档:

POST /test_index/_search
{
"query": {
"more_like_this": {
"fields": [
"text"
],
"like_text": "apple",
"min_term_freq": 1,
"percent_terms_to_match": 1,
"min_doc_freq": 1
}
}
}
...
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.5816214,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "1",
"_score": 0.5816214,
"_source": {
"text": "apple, apple, apple, apple, apple"
}
},
{
"_index": "test_index",
"_type": "doc",
"_id": "2",
"_score": 0.5254995,
"_source": {
"text": "apple, apple"
}
}
]
}
}

但是如果我将 "min_term_freq" 增加到 2(或更多),我什么也得不到,尽管我希望两个文档都被返回:

POST /test_index/_search
{
"query": {
"more_like_this": {
"fields": [
"text"
],
"like_text": "apple",
"min_term_freq": 2,
"percent_terms_to_match": 1,
"min_doc_freq": 1
}
}
}
...
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}

为什么?我错过了什么?

如果我想设置一个查询,只返回出现 5 次 "apple" 的文档,而不是出现 2 次的文档,有没有更好的方法?

为了方便起见,这里是代码:

http://sense.qbox.io/gist/341f9f77a6bd081debdcaa9e367f5a39be9359cc

最佳答案

最小术语频率和最小文档频率实际上在进行 MLT 之前应用于输入。这意味着由于您在输入文本中只出现了一次 apple,因此 apple 从未符合 MLT 的条件,因为最小词频设置为 2。如果您将输入更改为“apple apple”,如下所示,一切正常 -

POST /test_index/_search
{
"query": {
"more_like_this": {
"fields": [
"text"
],
"like_text": "apple apple",
"min_term_freq": 2,
"percent_terms_to_match": 1,
"min_doc_freq": 1
}
}
}

最小文档频率也是如此。 Apple 在至少 2 个文档中被发现,因此 min_doc_freq 高达 2 将有资格从输入文本应用到 MLT 操作。

关于Elasticsearch 更喜欢这个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28308196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com