【问题标题】:Elasticsearch Index type doesn't changed after updating statusElasticsearch 索引类型在更新状态后没有改变
【发布时间】:2023-04-08 21:40:01
【问题描述】:

我已经成功地进行了一些 _bulk 插入,现在我正在尝试使用日期范围进行查询并过滤如下内容:

{
   "query": {
        "bool": {
            "must": [{
                "terms": {
                    "mt_id": [613]
                }
            },
            {
                "range": {
                    "time": {
                        "gt": 1470009600000,
                        "lt": 1470009600000
                    }
                }
            }]
        }
    }

不幸的是我没有得到结果,现在我注意到索引映射是在批量插入之后创建的,如下所示:

{
  "agg__ex_2016_8_3": {
    "mappings": {
      "player": {
        "properties": {
          "adLoad": {
            "type": "long"
          },
         "mt_id": {
           "type": "long"
          },
          "time": {
            "type": "string"
          }
        }
      },

作为一种解决方案,我尝试使用以下方法更改索引映射:

PUT /agg__ex_2016_8_3/_mapping/player
{
  "properties" : {
    "mt_id" : {
      "type" :    "long",
      "index":    "not_analyzed"
    }
  }
}

得到

{
  "acknowledged": true
}

和 PUT /agg__ex_2016_8_3/_mapping/player

{
  "properties" : {
    "time" : {
      "type" :    "date",
     "format" : "yyyy/MM/dd HH:mm:ss"
    }
  }
}

得到:

{
   "error": {
      "root_cause": [
         {
            "type": "remote_transport_exception",
            "reason": "[vj_es_c1-esc13][10.132.69.145:9300][indices:admin/mapping/put]"
         }
      ],
      "type": "illegal_argument_exception",
      "reason": "mapper [time] of different type, current_type [string], merged_type [date]"
   },
   "status": 400
}

但是什么也没发生,仍然没有得到任何结果。

我做错了什么? (我必须使用 http,而不是 curl)

谢谢!!

【问题讨论】:

  • time 字符串类型的字段不太好。你能展示一个你认为应该匹配的示例文档吗?
  • Val: ,我已编辑问题文档:{ "_index": "agg__ex_2016_8_2", "_type": "player", "_id": "104", "_score": 4.244597, “_source”:{“时间”:“1470009600000”,“域”:“organisemyhouse.com”,“master_domain”:“613###organisemyhouse.com”,“playerRequets”:4,“playerLoads”:0“c_Id ": 0, "cb_Id": 0, "mt_Id": 613 } },

标签: elasticsearch indexing lucene elasticsearch-plugin sense


【解决方案1】:

试试这个:

# 1. delete index
DELETE agg__ex_2016_8_3

# 2. recreate it with the proper mapping
PUT agg__ex_2016_8_3
{
  "mappings": {
    "player": {
      "properties": {
        "adLoad": {
          "type": "long"
        },
        "mt_id": {
          "type": "long"
        },
        "time": {
          "type": "date"
        }
      }
    }
  }
}

# 3. create doc
PUT agg__ex_2016_8_3/player/104
{
  "time": "1470009600000",
  "domain": "organisemyhouse.com",
  "master_domain": "613###organisemyhouse.com",
  "playerRequets": 4,
  "playerLoads": 0,
  "c_Id": 0,
  "cb_Id": 0,
  "mt_Id": 613
}

# 4. search
POST agg__ex_2016_8_3/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "mt_Id": [
              613
            ]
          }
        },
        {
          "range": {
            "time": {
              "gte": 1470009600000,
              "lte": 1470009600000
            }
          }
        }
      ]
    }
  }
}

【讨论】:

  • 我使用具有以下结构的批量插入的问题:{index : { _index : agg_8_3_2016 , type : player, _id : i++ } }; ,它创建为默认日期“字符串”.....等,是否可以首先使用“批量插入”不同类型的日期创建,或者其他具有长的字段?谢谢 :) ,我不能一直重新创建索引,它的生产......
  • 您可以先执行第 1 步和第 2 步,然后您可以运行批量操作,它会将字符串时间戳正确解析为日期。
  • 第 2 步之后:GOT { "error": { "root_cause": [ { "type": "mapper_parsing_exception", "reason": "根映射定义有不受支持的参数:[mappings : {player ={ mt_Id={type=long}, playerLoads={type=long}, playerRequets={type=long}, time={type=date}}}}]" } ], "type": "mapper_parsing_exception", "原因”:“根映射定义具有不受支持的参数:[映射:{player=cb_Id={type=long},child_domain= time={type=date}}}}]”},“状态”:400 }
  • 请用您正在采取的确切步骤更新您的问题,目前尚不清楚您的案例出了什么问题以及您的索引状态。
  • 太棒了,它的作品非常感谢!日期查询类似于: "range": { "time": { "gt": "2016-08-01||/d", "lt": "2016-09-01||/d", " format": "yyyy-MM-dd" } } 是不是不能用"timestamp"查询? ,第二,我可以用“日期”类型创建批量吗? (不创建预映射)???
猜你喜欢
  • 1970-01-01
  • 2017-12-25
  • 2020-07-26
  • 1970-01-01
  • 1970-01-01
  • 2020-04-18
  • 2021-10-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多