简体   繁体   English

提供表达式的AWS Cloudsearch Ruby SDK错误:在期望JavaScript对象的地方发现无效值

[英]AWS Cloudsearch Ruby SDK errors on providing expressions: Found invalid value where JavaScript Object was expected

I am trying to use AWS cloudsearch from rails console. 我正在尝试从Rails控制台使用AWS cloudsearch。

I am trying to provide expressions to AWS cloudsearch searchRequest query. 我正在尝试向AWS cloudsearch searchRequest查询提供表达式。 It gives me error : "Found invalid value where JavaScript Object was expected" 它给我错误:“在期望JavaScript对象的地方找到了无效值”

I am able to provide a simple query string, a filter query and a query parser. 我能够提供一个简单的查询字符串,一个过滤器查询和一个查询解析器。

terminal : 终奌站 :

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 > 

Any help here will be greatly appreciated. 在这里的任何帮助将不胜感激。

Thanks, 谢谢,
Anshul 安舒尔

Error faced here is similar to the one asked in AWS forums : https://forums.aws.amazon.com/thread.jspa?messageID=579640 此处遇到的错误类似于AWS论坛中提出的错误: https : //forums.aws.amazon.com/thread.jspa? messageID =579640

Solution is to create a map for expressions, where each |key,value| 解决方案是为表达式创建一个映射,其中每个| key,value | denotes expressions name and its formula(value). 表示表达式名称及其公式(值)。 And pass the JsonEncoded string of this map to the search method of cloudSearchDomain. 并将此映射的JsonEncoded字符串传递给cloudSearchDomain的搜索方法。

eg 例如

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> – 

Your expr param of '1' is not valid, as it violates this requirement: 您的expr参数'1'无效,因为它违反了此要求:

Expression names must begin with a letter and be at least 3 and no more than 64 characters long. The following characters are allowed: a-z (lower-case letters), 0-9, and _ (underscore). The name score is reserved and cannot be used as an expression name.

If you aren't trying to use a named expression, remove the quotes, since a ranking expression must return an integer. 如果您不尝试使用命名表达式,请删除引号,因为排名表达式必须返回整数。

See http://docs.aws.amazon.com/cloudsearch/latest/developerguide/configuring-expressions.html 参见http://docs.aws.amazon.com/cloudsearch/latest/developerguide/configuring-expressions.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM