opensearch-project / opensearch-ruby

Ruby Client for OpenSearch
Apache License 2.0
90 stars 46 forks source link

[FEATURE] Add script_score to query DSL #253

Closed quangcap closed 1 week ago

quangcap commented 2 weeks ago

Is your feature request related to a problem?

Script Score query was added to OpenSearch 2.9 and current query DSL does not support it. I use script score a lot in my case, so I would want to add it in current query DSL.

What solution would you like?

Add script_score to query DSL

Do you have any additional context?

OpenSearch document on script_score: https://opensearch.org/docs/latest/query-dsl/specialized/script-score/

dblock commented 2 weeks ago

Related, we've been working on https://github.com/opensearch-project/opensearch-api-specification. For this client we need help for someone to pickup https://github.com/opensearch-project/opensearch-ruby/issues/233 and other generator-related work.

@quangcap Now that you're very familiar with this API, would you be able to contribute it to the spec as well? https://github.com/opensearch-project/opensearch-api-specification

dblock commented 1 week ago

Closed via https://github.com/opensearch-project/opensearch-ruby/pull/254.

quangcap commented 2 days ago

@dblock Sorry for the late reply!

About #233: I tried out the ApiGenerator, and it throws a lot of errors, probably because the current parser doesn’t support OAS 3.1 yet. I’ve seen some work being done on the parser (https://github.com/kevindew/openapi3_parser/pull/22), but I don’t think it’ll be ready anytime soon.

As for adding script_score to the spec: Absolutely, I’d love to help out! But I believe script_score query is added in the spec.

dblock commented 2 days ago

FWIW, I've been able to load the spec with the current openapi3_parser:

require 'open-uri'
require 'openapi3_parser'

openapi_url = "https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml"
openapi_path = "opensearch-openapi.yaml"
File.write(openapi_path, URI.open(openapi_url).read) unless File.exists?(openapi_path)
puts "Loading #{openapi_path} (#{File.size(openapi_path)} byte(s)) ..."

doc = Openapi3Parser.load_file(openapi_path)
puts "Loaded #{openapi_url} with #{doc.paths.size} path(s)."

doc.paths.keys.each do |key|
   puts key
end
quangcap commented 2 days ago

I've been able to load it with the current openapi3_parser. However, running .valid? and .errors, I can print out a lot of errors.

...
doc = Openapi3Parser.load_file(openapi_path)
puts "Loaded #{openapi_url} with #{doc.paths.size} path(s)."
puts "Spec is valid: " + doc.valid?.to_s

puts "Errors:"
doc.errors.each do |err|
  puts err
end

which prints:

Loading opensearch-openapi.yaml (1885141 byte(s)) ...
Loaded https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml with 320 path(s).
Spec is valid: false
Errors:
#/components/parameters/_global%3A%3Aquery.pretty does not resolve to a valid object
#/components/parameters/_global%3A%3Aquery.human does not resolve to a valid object
#/components/parameters/_global%3A%3Aquery.error_trace does not resolve to a valid object
#/components/parameters/_global%3A%3Aquery.pretty does not resolve to a valid object
#/components/parameters/_global%3A%3Aquery.human does not resolve to a valid object
#/components/parameters/_global%3A%3Aquery.error_trace does not resolve to a valid object
#/components/parameters/_global%3A%3Aquery.pretty does not resolve to a valid object
#/components/parameters/_global%3A%3Aquery.human does not resolve to a valid object
#/components/parameters/_global%3A%3Aquery.error_trace does not resolve to a valid object
...
dblock commented 2 days ago

@quangcap Do you know whether those are legit errors? If they are, please do open an issue in https://github.com/opensearch-project/opensearch-api-specification.