我正在尝试将twitter流式传输到elasticsearch。如果我在流式传输之前不创建任何索引,我没有问题,但是这样我就无法按日期过滤并创建时间线。我尝试使用这个映射:
https://gist.github.com/christinabo/ca99793a5d160fe12fd9a31827e74444
据称,这允许ES正确选择"日期",但我在创建索引时收到此错误:
"type":"illegal_argument_exception","原因":"未知设置[index. twitter.map._doc.properties.coordinates.properties.协调员.type]请检查是否安装了任何必需的插件,或检查中断更改留档以删除设置"
怎么了?
谢谢
我正在运行这个python脚本。之前,我试图用PUTtwitter_stream设置来自开发工具的映射。抱歉,可怕的缩进!
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)
阅读日期字段注释后,推文的日期格式不是支持的默认格式之一。
为了让ElasticSearch理解,作为一个日期字段,您应该为twitter_stream
索引指定一个自定义映射,在这个映射中,您可以知道推文日期字段的日期格式。解释可自定义日期格式的语法在这里。
因此,如果您使用的是Elasticsearch 7. X,则可以通过以下方式指定自定义格式:
PUT twitter_stream
{
"mappings": {
"properties": {
"YOUR_TWEETS_DATE_FIELD": {
"type": "date",
"format": "EEE LLL dd HH:mm:ss Z yyyy"
}
}
}
}
您可以将上述配置复制并执行到Kibanadev tools控制台。然后,尝试再次运行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将使用其动态映射定义其余字段和类型。