Python、AWS Elasticsearch 迁移到 Azure

发布于 2025-01-11 05:47:09 字数 2277 浏览 0 评论 0原文

我完全构建了这个项目并将其推送到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

路弥 2025-01-18 05:47:09

问题是我使用 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#

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文