获取整个索引的总词频(Elasticsearch)
Getting total term frequency throughout entire index (Elasticsearch)
我正在尝试计算特定术语在整个索引中出现的总次数(术语收集频率)。我试图通过使用术语向量来做到这一点,但这仅限于单个文档。即使在特定文档中存在术语的情况下,响应似乎在某个 doc_count(在 field_statistics 内)时达到最大值,这让我怀疑它的准确性。
要求:
http://myip:9200/clinicaltrials/trial/AVmk-ky6XMskTDwIwpih/_termvectors?term_statistics=true
此处使用的文档 ID 是 "AVmk-ky6XMskTDwIwpih",但术语统计信息不应特定于文档。
回复:
这是我得到的术语 "cancer" 的其中一个字段:
"cancer" : {
"doc_freq" : 5297,
"ttf" : 10587,
"term_freq" : 1,
"tokens" : [
{
"position" : 15,
"start_offset" : 115,
"end_offset" : 121
}
]
},
如果我对所有字段的 ttf 求和,我得到 18915。但是,"cancer" 的实际总词频实际上是 542829。这让我相信它限制了 term_vector 索引中文档子集的统计信息。
如有任何建议,我们将不胜感激。
我认为您需要根据 elasticsearch documentation 将 term_statistics 变为真:
Term statistics
Setting term_statistics to true (default is false) will return
total term frequency (how often a term occurs in all documents)
document frequency (the number of documents containing the current term)
By default these values are not returned since term statistics can have a serious performance impact.
计数不同的原因是术语向量不准确,除非所讨论的索引只有一个分片。对于具有多个分片的索引,文档分布在所有分片中,因此返回的频率不是总数而是来自随机选择的分片。
因此,返回的频率只是一个相对值,而不是您期望的绝对值。 see the Behaviour section。
要对此进行测试,您可以创建单个分片索引并请求频率(它应该会为您提供实际总数)。
您试过只使用 COUNT API 吗?
https://www.elastic.co/guide/en/elasticsearch/reference/7.6/search-count.html
它可以return查询匹配的数量。所以这样的事情可能会奏效。
GET /my_index/_count
{
"query" : {"match": {"my_field": "my_keyword"}
}
我正在尝试计算特定术语在整个索引中出现的总次数(术语收集频率)。我试图通过使用术语向量来做到这一点,但这仅限于单个文档。即使在特定文档中存在术语的情况下,响应似乎在某个 doc_count(在 field_statistics 内)时达到最大值,这让我怀疑它的准确性。
要求:
http://myip:9200/clinicaltrials/trial/AVmk-ky6XMskTDwIwpih/_termvectors?term_statistics=true
此处使用的文档 ID 是 "AVmk-ky6XMskTDwIwpih",但术语统计信息不应特定于文档。
回复:
这是我得到的术语 "cancer" 的其中一个字段:
"cancer" : {
"doc_freq" : 5297,
"ttf" : 10587,
"term_freq" : 1,
"tokens" : [
{
"position" : 15,
"start_offset" : 115,
"end_offset" : 121
}
]
},
如果我对所有字段的 ttf 求和,我得到 18915。但是,"cancer" 的实际总词频实际上是 542829。这让我相信它限制了 term_vector 索引中文档子集的统计信息。
如有任何建议,我们将不胜感激。
我认为您需要根据 elasticsearch documentation 将 term_statistics 变为真:
Term statistics Setting term_statistics to true (default is false) will return
total term frequency (how often a term occurs in all documents)
document frequency (the number of documents containing the current term)
By default these values are not returned since term statistics can have a serious performance impact.
计数不同的原因是术语向量不准确,除非所讨论的索引只有一个分片。对于具有多个分片的索引,文档分布在所有分片中,因此返回的频率不是总数而是来自随机选择的分片。
因此,返回的频率只是一个相对值,而不是您期望的绝对值。 see the Behaviour section。 要对此进行测试,您可以创建单个分片索引并请求频率(它应该会为您提供实际总数)。
您试过只使用 COUNT API 吗? https://www.elastic.co/guide/en/elasticsearch/reference/7.6/search-count.html
它可以return查询匹配的数量。所以这样的事情可能会奏效。
GET /my_index/_count
{
"query" : {"match": {"my_field": "my_keyword"}
}