1

我正在尝试查询每个会话中生成的平均请求,我在将数据放入索引时插入了一个 session_id,我想计算不同的会话并取出平均值,同时检查我知道的数据映射它在文本字段中:

"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
  }
}
4

1 回答 1

2

虽然我没有完全检查您的查询,但关键字字段的名称似乎已关闭。的关键字字段session_idsession_id.keyword根据提供的映射

于 2020-01-27T13:52:07.450 回答