gpt4 book ai didi

javascript - AWS Cloudsearch Ruby SDK 在提供表达式时出现错误 : Found invalid value where JavaScript Object was expected

转载 作者:行者123 更新时间:2023-12-03 09:37:35 27 4
gpt4 key购买 nike

我正在尝试从 Rails 控制台使用 AWS cloudsearch。

我正在尝试为 AWS cloudsearch searchRequest 查询提供表达式。它给了我错误:“在需要 JavaScript 对象的地方发现无效值”

我能够提供一个简单的查询字符串、一个过滤器查询和一个查询解析器。

终端:

Aws.config.update({region: 'us-west-2',credentials: Aws::Credentials.new(‘key_id', ’secret_key'), })
csd = Aws::CloudSearchDomain::Client.new(region: 'us-east-1', endpoint: 'http://search-endpoint.us-east-1.cloudsearch.amazonaws.com/')

1.9.3-p551 :340 >
1.9.3-p551 :341 > fq
=> "location:['40.628611,-100.694152','25.621966,-66.686706']"
1.9.3-p551 :342 > csd
=> #<Aws::CloudSearchDomain::Client>
1.9.3-p551 :343 > csd.search(query:'user*', query_parser:'simple', filter_query: fq)
=> #<struct Aws::CloudSearchDomain::Types::SearchResponse status=#<struct Aws::CloudSearchDomain::Types::SearchStatus timems=11, rid="5/L54eYpoqkBCluMDg==">, hits=#<struct Aws::CloudSearchDomain::Types::Hits found=0, start=0, cursor=nil, hit=[]>, facets=nil>
1.9.3-p551 :344 > csd.search(query:'user*', query_parser:'simple', filter_query: fq, expr:'1')
Aws::CloudSearchDomain::Errors::SearchException: Invalid syntax in 'expr' parameter: Found invalid value where JavaScript Object was expected
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/aws-sdk-core-2.1.2/lib/seahorse/client/plugins/raise_response_errors.rb:15:in `call'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/aws-sdk-core-2.1.2/lib/aws-sdk-core/plugins/param_converter.rb:21:in `call'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/aws-sdk-core-2.1.2/lib/aws-sdk-core/plugins/response_paging.rb:26:in `call'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/aws-sdk-core-2.1.2/lib/seahorse/client/plugins/response_target.rb:18:in `call'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/aws-sdk-core-2.1.2/lib/seahorse/client/request.rb:70:in `send_request'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/aws-sdk-core-2.1.2/lib/seahorse/client/base.rb:207:in `block (2 levels) in define_operation_methods'
from (irb):344
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/railties-4.2.3/lib/rails/commands/console.rb:110:in `start'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/railties-4.2.3/lib/rails/commands/console.rb:9:in `start'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
from /Users/anshulgoyal/workspace/adamantium/backend/truckfinder_service/bin/rails:8:in `<top (required)>'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/anshulgoyal/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
from /Users/anshulgoyal/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/anshulgoyal/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'1.9.3-p551 :345 >

这里的任何帮助将不胜感激。

谢谢,
安舒尔

最佳答案

此处遇到的错误与 AWS 论坛中提出的错误类似: https://forums.aws.amazon.com/thread.jspa?messageID=579640

解决方案是为表达式创建一个映射,其中每个 |key,value|表示表达式名称及其公式(值)。并将该 map 的 JsonEncoded 字符串传递给 cloudSearchDomain 的搜索方法。

例如

1.9.3-p551 :520 > expr_map2 

=> {:geo=>"haversin(38.958687,-77.343149,location.latitude,location.longitude)"}

1.9.3-p551 :521 > csd.search(query:'user*', query_parser:'simple', filter_query: fq, expr:ActiveSupport::JSON.encode(expr_map2))

=> #<struct Aws::CloudSearchDomain::Types::SearchResponse status=#<struct Aws::CloudSearchDomain::Types::SearchStatus timems=45, rid="wPzUhOcp7rIBCluMDg==">, hits=#<struct Aws::CloudSearchDomain::Types::Hits found=0, start=0, cursor=nil, hit=[]>, facets=nil> –

关于javascript - AWS Cloudsearch Ruby SDK 在提供表达式时出现错误 : Found invalid value where JavaScript Object was expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31284739/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com