Elasticsearch:无法将文档添加到索引

2024-06-02 06:43:55 发布

您现在位置:Python中文网/ 问答频道 /正文

使用tweepy和elasticsearch Python模块,我可以创建索引,但是不能创建/添加文档。我从一个对作者有用的例子中获取了代码(不是一直都是这样吗)。在

#!/usr/bin/env python
#
import tweepy
import sys
import json
from textwrap import TextWrapper
from datetime import datetime
from elasticsearch import Elasticsearch

consumer_key = "abcd"
consumer_secret = "1234"
access_token = "qwerty-5678"
access_secret = "huffalump"

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)

es = Elasticsearch()

#es.indices.create(index="twitter", ignore=400)

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

    def on_status(self, status):
        try:
            print 'n%s %s' % (status.author.screen_name, status.created_at)

            json_data = status._json
            print json_data['text']

            es.create(index="twitter", doc_type="twitter_twp", body=json_data)

        except Exception, e:
            print e
            pass

streamer = tweepy.Stream(auth=auth, listener=StreamListener(), timeout=3000000000 )

#Fill with your own Keywords below
terms = ['cyber']

streamer.filter(None,terms)
#streamer.userstream(None)

我在http://192.168.1.7:9200/_cat/indices?v处监视我的Elasticsearch索引,数据从不更改:

^{pr2}$

我什么都试过了-甚至读过医生。为什么我的文档不在我的索引中!?在


Tags: fromimporttokenauthjsonsecretaccesses