Php 带文本字段的Elasticsearch基数聚合
我试图查询每个会话中生成的平均请求,我在将数据放入索引时插入会话id,我想计算不同的会话数并取平均值,同时检查数据的映射,我知道它在文本字段中:Php 带文本字段的Elasticsearch基数聚合,php,
elasticsearch,elasticsearch-php,Php,
elasticsearch,Elasticsearch Php,我试图查询每个会话中生成的平均请求,我在将数据放入索引时插入会话id,我想计算不同的会话数并取平均值,同时检查数据的映射,我知道它在文本字段中: "session_id": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, 要获取我调用的数据,请执行以下操作: $this->el
"session_id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
要获取我调用的数据,请执行以下操作:
$this->elasticsearch->search([
'index' => 'nits_media_bid_won',
'body' => [
'query' => $query,
'aggs' => [
'total_session' => [
'cardinality' => [
'field' => 'session_id',
'precision_threshold' => 100,
]
]
]
]
]);
但我得到了一个错误声明:
{
"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
}
如果我按照关键字进行更改:
'total_session' => [
'cardinality' => [
'field' => 'session_id.fields.keyword',
'precision_threshold' => 100,
]
]
它给了我0的值
"aggregations": {
"total_session": {
"value": 0
}
}
虽然我没有完全检查您的查询,但关键字字段的名称似乎已关闭。根据提供的映射,
session\u id
的关键字字段将是session\u id.keyword