han*_*kim 5 amazon-web-services elasticsearch
我有很多数据要发送到 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我看不到任何插入数据的方法。
这似乎是非常基本的工作。有什么帮助吗?
您可以使用 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"))
Run Code Online (Sandbox Code Playgroud)
编辑
确认数据是否推送到你索引下的elastic cache,可以尝试通过替换域名和索引名来做一个HTTP GET
search-my-domain.us-west-1.es.amazonaws.com/_search?q=movies
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3789 次 |
| 最近记录: |