【问题标题】:Elasticsearch: Apply a lowercase on indexed dataElasticsearch:对索引数据应用小写
【发布时间】:2017-09-14 12:40:49
【问题描述】:

我在我的 elasticsearch 中索引了文档。示例文档如下所示:

{
    "_index": "processed_tweets",
    "_type": "processed",
    "_id": "830403820580663296",
    "_score": 1,
    "_source": {
      "at": [
        "@LouisDasch"
      ],
      "original_tweet_id": "830398288352403457",
      "id_str": "830403820580663296",
      "trigrams": [
        "blessed lourdes lady",
        "lourdes lady feast",
        "lady feast day",
        "feast day wishing"
      ],
      "hashtags": [
        "#Catholic"
      ],
      "id_tweet_creator": "487735029",
      "tokens": [
        "blessed",
        "lourdes",
        "lady",
        "feast",
        "day",
        "wishing"
      ],
      "bigrams": [
        "blessed lourdes",
        "lourdes lady",
        "lady feast",
        "feast day",
        "day wishing"
      ],
      "retweeted": true
    }
  }

我想将我已索引的所有文档的“主题标签”字段中的所有主题标签小写。 例如我会有: “标签”:[“#Catholic”]->“标签”:[“#catholic”] 将每个关键字更新为等效的小写字母(保留“#”)的最佳方法是什么(耗时更少)?

【问题讨论】:

  • 它们都遵循相同的结构吗?
  • @depperm 实际上我的解决方案是完全重新索引,但我想知道是否有替代方案
  • @DmitryPolonskiy 某些文档可能缺少 original_tweet_id

标签: python elasticsearch lucene


【解决方案1】:

如果您使用的是 ES 5.0 及更高版本,则引入了一种称为“无痛”的脚本语言。这可以帮助您更新字段。它的处理速度非常快。

查看以下链接了解更多信息。

https://www.elastic.co/guide/en/elasticsearch/reference/5.0/modules-scripting-painless.html

【讨论】:

  • “版本”:{“数字”:“5.2.1”、“build_hash”:“db0d481”、“build_date”:“2017-02-09T22:05:32.386Z”、“build_snapshot” " : false, "lucene_version" : "6.4.1" }
  • 你能提供一个更具描述性的例子吗?
  • //尝试类似这样 POST processes_tweets/processed/_update_by_query { "script": { "lang": "painless", "inline": "ctx._source.hashtags = ctx._source.hashtags .replaceAll(/#*/, m -> m.group().toUpperCase(Locale.ROOT))" } }
猜你喜欢
  • 2019-07-15
  • 2013-06-23
  • 2012-01-26
  • 2015-01-22
  • 2018-07-25
  • 1970-01-01
  • 1970-01-01
  • 2014-09-08
  • 2016-01-25
相关资源
最近更新 更多