Python、AWS Elasticsearch 迁移到 Azure
我完全构建了这个项目并将其推送到 AWS,Elasticsearch 查询效果非常好。现在我已经通过 Azure 进行了身份验证。创建了我的索引,并且可以执行简单的“选择所有查询”并取回记录。但是,当我尝试让原来的 AWS elasticsearch 查询工作时,它就是拒绝工作。
您能帮我解决我的疑问吗?
AWS 代码 此代码正在 AWS 上运行并投入生产。随着我们迁移到 Azure,它即将退役。
def request_search():
try:
error = None
if request.method == 'POST':
host = ''
region = 'us-west-2'
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
)
search_term = request.form['input']
res= es.search(index=myindex, scroll = '2m', doc_type='_doc',body={
"query": {
"multi_match" : {
"query": search_term,
"fields": [ "creator", "date", "receipt", "sales", "category"],
"fuzziness" : "AUTO",
"prefix_length" : 0
}
}
},
size=1000)
res['ST']=search_term
return render_template('results.html', res=res, search_term=search_term)
else:
#return to search page.
return render_template('index.html')
except Exception as e:
return render_template("404_generic", error = str(e))
Azure 代码 - 不起作用
if request.method == 'POST':
#search_term = "Hotel"
search_term = request.form['input']
#print("The search term is: " + search_term)
res= es.search(index="myindex", scroll = '2m', doc_type='_doc', query={
"multi_match" : {
"query": "search_term",
"fuzziness": 2,
"fields": [ "creator", "date", "receipt", "sales", "category"],
"fuzziness" : "AUTO",
"prefix_length" : 0
}
},
size=1000)
res['ST']=search_term
return render_template('index.html',
res=res,
search_term=search_term
)
I had this project completely built and pushed to AWS, the Elasticsearch queries worked great. Now I've authenticated with Azure. Created my index, and can do a simple "select all query" and get records back. But, when I try to get my original AWS elasticsearch query to work it just refuses to work.
Would you please help me fix my query?
AWS Code this code was working and in production on AWS. It is being retired as we move to Azure.
def request_search():
try:
error = None
if request.method == 'POST':
host = ''
region = 'us-west-2'
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
)
search_term = request.form['input']
res= es.search(index=myindex, scroll = '2m', doc_type='_doc',body={
"query": {
"multi_match" : {
"query": search_term,
"fields": [ "creator", "date", "receipt", "sales", "category"],
"fuzziness" : "AUTO",
"prefix_length" : 0
}
}
},
size=1000)
res['ST']=search_term
return render_template('results.html', res=res, search_term=search_term)
else:
#return to search page.
return render_template('index.html')
except Exception as e:
return render_template("404_generic", error = str(e))
Azure Code -- Does not work
if request.method == 'POST':
#search_term = "Hotel"
search_term = request.form['input']
#print("The search term is: " + search_term)
res= es.search(index="myindex", scroll = '2m', doc_type='_doc', query={
"multi_match" : {
"query": "search_term",
"fuzziness": 2,
"fields": [ "creator", "date", "receipt", "sales", "category"],
"fuzziness" : "AUTO",
"prefix_length" : 0
}
},
size=1000)
res['ST']=search_term
return render_template('index.html',
res=res,
search_term=search_term
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是我使用 Azure 认知搜索从 AWS 迁移到 Azure,而不是专门使用 ElasticSearch。本指南有助于迁移并消除混乱。
https://azuresdkdocs。 blob.core.windows.net/$web/python/azure-search/1.0.0b1/index.html#
The issue is that I'm using Azure Cognitive Search for the migration from AWS to Azure, not specifically ElasticSearch. This guide has helped the migration and clear up confusion.
https://azuresdkdocs.blob.core.windows.net/$web/python/azure-search/1.0.0b1/index.html#