【问题标题】:input data to aws elasticsearch using boto3 or es library使用 boto3 或 es 库将数据输入到 aws elasticsearch
【发布时间】:2020-07-13 23:28:09
【问题描述】:

我有很多数据要发送到 aws elasticsearch。通过查看https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-gsg-upload-data.html aws 网站,它使用 curl -Xput 但是我想使用 python 来执行此操作,因此我查看了 boto3 文档但找不到输入数据的方法。

https://boto3.amazonaws.com/v1/documentation/api/1.9.42/reference/services/es.html我看不到任何插入数据的方法。

这似乎是非常基本的工作。有什么帮助吗?

【问题讨论】:

    标签: amazon-web-services elasticsearch


    【解决方案1】:

    您可以使用 HTTP 接口将数据发送到弹性搜索。以下是来自

    的代码

    https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-request-signing.html

    from requests_aws4auth import AWS4Auth
    import boto3
    
    host = '' # For example, my-test-domain.us-east-1.es.amazonaws.com
    region = '' # e.g. us-west-1
    
    service = 'es'
    credentials = boto3.Session().get_credentials()
    awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)
    
    es = Elasticsearch(
        hosts = [{'host': host, 'port': 443}],
        http_auth = awsauth,
        use_ssl = True,
        verify_certs = True,
        connection_class = RequestsHttpConnection
    )
    
    document = {
        "title": "Moneyball",
        "director": "Bennett Miller",
        "year": "2011"
    }
    
    es.index(index="movies", doc_type="_doc", id="5", body=document)
    
    print(es.get(index="movies", doc_type="_doc", id="5"))
    

    编辑

    要确认数据是否推送到你的索引下的弹性缓存,你可以尝试通过替换域名和索引名来做一个HTTP GET

    search-my-domain.us-west-1.es.amazonaws.com/_search?q=movies 
    

    【讨论】:

    • es.index 是否为我创建索引?
    • 我收到 ConnectionError: ConnectionError(HTTPSConnectionPool(host='https', port=443):
    • 你的 Elastic 主机放好了吗?
    • 是的,现在它可以工作了,但是我在 kibana 中看不到输入的数据...
    • 您能否通过在您的弹性缓存索引上发出 HTTP GET 来确认数据是否被推送到弹性缓存中?像这样 GET search-my-domain.us-west-1.es.amazonaws.com/_search?q=house
    猜你喜欢
    • 2019-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-29
    相关资源
    最近更新 更多