[英]Elasticsearch cardinality aggregation with text fields
I'm trying to query out average request generated in per session, I'm inserting a session_id while putting the data in my indices, I want to count distinct sessions and take out the average, while checking the mapping of data I came to know that it is in text field:我正在尝试查询每个会话中生成的平均请求,我在将数据放入索引时插入 session_id,我想计算不同的会话并取出平均值,同时检查我知道的数据映射它在文本字段中:
"session_id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
For fetching the data I call:为了获取我调用的数据:
$this->elasticsearch->search([
'index' => 'nits_media_bid_won',
'body' => [
'query' => $query,
'aggs' => [
'total_session' => [
'cardinality' => [
'field' => 'session_id',
'precision_threshold' => 100,
]
]
]
]
]);
But I get an error stating:但我收到一条错误消息:
{
"error":{
"root_cause":[
{
"type":"illegal_argument_exception",
"reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [session_id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
],
"type":"search_phase_execution_exception",
"reason":"all shards failed",
"phase":"query",
"grouped":true,
"failed_shards":[
{
"shard":0,
"index":"nits_media_bid_won",
"node":"q438L5GRSqaHJz1_vRtZXg",
"reason":{
"type":"illegal_argument_exception",
"reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [session_id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
}
],
"caused_by":{
"type":"illegal_argument_exception",
"reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [session_id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.",
"caused_by":{
"type":"illegal_argument_exception",
"reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [session_id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
}
},
"status":400
}
If I do the change as per the keyword:如果我按照关键字进行更改:
'total_session' => [
'cardinality' => [
'field' => 'session_id.fields.keyword',
'precision_threshold' => 100,
]
]
It gives me 0 value它给了我 0 值
"aggregations": {
"total_session": {
"value": 0
}
}
While I didn't fully check your query it appears that the name for the keyword field is off.虽然我没有完全检查您的查询,但似乎关键字字段的名称已关闭。 The keyword field of
session_id
would be session_id.keyword
according to the supplied mapping session_id
的关键字字段将是session_id.keyword
根据提供的映射
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.