Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] missing definition in termsQuery #540

Closed
amberzsy opened this issue Aug 29, 2024 · 10 comments · Fixed by #564 or #570
Closed

[BUG] missing definition in termsQuery #540

amberzsy opened this issue Aug 29, 2024 · 10 comments · Fixed by #564 or #570
Assignees
Labels
bug Something isn't working

Comments

@amberzsy
Copy link
Contributor

amberzsy commented Aug 29, 2024

What is the bug?

termsQuery has Object without properties defined

@amberzsy amberzsy added bug Something isn't working untriaged labels Aug 29, 2024
@prudhvigodithi
Copy link
Contributor

prudhvigodithi commented Aug 30, 2024

[Triage]
Going over this link https://opensearch.org/docs/latest/query-dsl/term/terms/ and seeing the https://github.com/opensearch-project/opensearch-api-specification code, does adding the following make sense?

TermsQuery:
  allOf:
    - $ref: '#/components/schemas/QueryBase'
    - type: object
      properties:
        terms:
          type: object
          description: A JSON object containing the field name and either an array of terms or an object for term lookup.
          additionalProperties:
            oneOf:
              - type: array
                items:
                  type: string
                description: Array of terms you wish to find in the specified field.
              - type: object
                properties:
                  index:
                    $ref: '_common.yaml#/components/schemas/IndexName'
                  id:
                    $ref: '_common.yaml#/components/schemas/Id'
                  path:
                    $ref: '_common.yaml#/components/schemas/Field'
                  routing:
                    $ref: '_common.yaml#/components/schemas/Routing'
                description: Object for fetching terms.
      required:
        - terms

The QueryBase already has boost so dont need to add again to properties.

Thank you
@amberzsy @dblock @getsaurabh02.

@dblock
Copy link
Member

dblock commented Aug 30, 2024

I would introduce a Term for parts of this.

Either way start by writing a test that exercises this API and then the schema.

@prudhvigodithi prudhvigodithi self-assigned this Aug 30, 2024
@prudhvigodithi
Copy link
Contributor

@amberzsy
Copy link
Contributor Author

I would introduce a Term for parts of this.

+1

@nhtruong
Copy link
Collaborator

nhtruong commented Sep 5, 2024

Seems like the Search API has a lot of holes to patch. This one is related: #529

I'll look into the old ES spec (right before OS was forked) to see what's missing and cross check with the new features of this API that are unique to OS.

@prudhvigodithi
Copy link
Contributor

Thanks @nhtruong, since the PR to add the missing definition for termsQuery is merged can we close this issue and open a new ones for patches that has to be added to Search API?
@dblock @amberzsy

@dblock
Copy link
Member

dblock commented Sep 6, 2024

Yes, please. Closing this one.

@dblock dblock closed this as completed Sep 6, 2024
@amberzsy
Copy link
Contributor Author

amberzsy commented Sep 9, 2024

@prudhvigodithi @dblock

why we use different definition from #540 (comment) in the PR.

I did quick testing on

TermsQuery:
  allOf:
    - $ref: '#/components/schemas/QueryBase'
    - type: object
      properties:
        terms:
          type: object
          description: A JSON object containing the field name and either an array of terms or an object for term lookup.
          additionalProperties:
            oneOf:
              - type: array
                items:
                  type: string
                description: Array of terms you wish to find in the specified field.
              - type: object
                properties:
                  index:
                    $ref: '_common.yaml#/components/schemas/IndexName'
                  id:
                    $ref: '_common.yaml#/components/schemas/Id'
                  path:
                    $ref: '_common.yaml#/components/schemas/Field'
                  routing:
                    $ref: '_common.yaml#/components/schemas/Routing'
                description: Object for fetching terms.
      required:
        - terms

the JSON will be as below, which looks correct.

{
    "terms": 
             "string_key": {
                    "index": "something", 
                    "id": "id_1",
                    ...
               }

}

however with what defined in PR, here

Terms: 
  oneOf:
        - type: array
          items:
            type: string
        - type: object
          properties:
            index:
              $ref: '_common.yaml#/components/schemas/IndexName'
            id:
              $ref: '_common.yaml#/components/schemas/Id'
            path:
              $ref: '_common.yaml#/components/schemas/Field'
            routing:
              $ref: '_common.yaml#/components/schemas/Routing'
          additionalProperties: true
          description: Object for fetching terms.

the JSON will be missing <field_name>

@prudhvigodithi
Copy link
Contributor

Hey @amberzsy only difference from my comment and PR is is just created a new schema Terms so that both the TermsQuery and TermsSetQuery can leverage the Terms schema.

@Xtansia
Copy link
Collaborator

Xtansia commented Sep 10, 2024

@amberzsy @prudhvigodithi I've just made a fix to correct the position of the additionalProperties and anyOf/oneOf on the terms query in #564

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants