无法使用elasticsearch + kibana + twitter正确映射日期

问题描述 投票:0回答:2

我正在尝试将twitter流式传输到elasticsearch。如果我不在流媒体之前创建任何索引,我没有任何问题,但以这种方式我不能按日期过滤并创建时间表。我试图使用这个映射:

https://gist.github.com/christinabo/ca99793a5d160fe12fd9a31827e74444

据称允许ES正确选择“日期”,但我在创建索引时收到此错误:

“type”:“illegal_argument_exception”,“reason”:“未知设置[index.twitter.mappings._doc.properties.coordinates.properties.coordinates.type]请检查是否安装了所需的插件,或查看更改文档删除设置“

怎么了?

谢谢

elasticsearch twitter
2个回答
0
投票

我正在运行这个python脚本。之前,我尝试使用PUT twitter_stream设置Dev Tools的映射。抱歉可怕的缩进!

    es = Elasticsearch("https://admin:admin@localhost:9200", 
    verify_certs=False)
    es.indices.create(index='twitter_stream', ignore=400)

    class StreamApi(tweepy.StreamListener):
    status_wrapper = TextWrapper(width=60, initial_indent='    ', 
   subsequent_indent='    ')

    def on_status(self, status):

  json_data = status._json

   es.index(index="twitter_stream",
          doc_type="twitter",
              body=json_data,
      ignore=400
          )

   streamer = tweepy.Stream(auth=auth, listener=StreamApi(), timeout=30)

    terms = ['#assange', 'assange']

    streamer.filter(None,terms) 

0
投票

阅读日期字段注释后,推文的日期格式不是default formats supported之一。

要让ElasticSearch了解作为日期字段,您应该为twitter_stream索引指定一个自定义映射,您可以在其中告知您对tweets日期字段的预期日期格式。解释可自定义日期格式的语法是here

因此,如果您使用的是Elasticsearch 7.X,则可以通过以下方式指定自定义格式:

PUT twitter_stream
{
  "mappings": {
    "properties": {
      "YOUR_TWEETS_DATE_FIELD": {
        "type":   "date",
        "format": "EEE LLL dd HH:mm:ss Z yyyy"
      }
    }
  }
}

您可以将上述配置复制并执行到Kibana dev工具控制台。然后,再次尝试运行pyhton脚本。解释格式中使用的字母:

E       day-of-week                 text              Tue; Tuesday; T
M/L     month-of-year               number/text       7; 07; Jul; July; J
d       day-of-month                number            10
H       hour-of-day (0-23)          number            0
m       minute-of-hour              number            30
s       second-of-minute            number            55
Z       zone-offset                 offset-Z          +0000; -0800; -08:00;
y       year-of-era                 year              2004; 04

此外,无需在映射中定义任何其他内容。 ElasticSearch将使用其动态映射定义其余字段和类型。

© www.soinside.com 2019 - 2024. All rights reserved.