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

Construct body with 'boosts' according to the current API #174

Closed
wants to merge 1 commit into from

Conversation

groeney
Copy link

@groeney groeney commented Oct 2, 2023

See documentation here: https://www.elastic.co/guide/en/app-search/8.9/relevance-tuning-guide.html#relevance-tuning-guide-weights-and-boosts-boosts-via-api

The current bug can be reproduced with:

>>> from elastic_enterprise_search import AppSearch
>>> app_search_client = AppSearch(
...     HOST,
...     bearer_auth=API_KEY,
... )
>>> query="robot"
>>> 
>>> results = app_search_client.search(
...     engine_name=ENGINE, query=query, page_size=10
... )
>>> len(results['results'])
10
>>> boosts = {
...     "num_interactions": [
...         {
...             "type": "functional",
...             "function": "logarithmic",
...             "operation": "add",
...             "factor": 3.5,
...         }
...     ]
... }
>>> 
>>> results2 = app_search_client.search(
...     engine_name=ENGINE, query=query, page_size=10, boost=boosts
... )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/lib/python3.11/site-packages/elastic_enterprise_search/_utils.py", line 454, in wrapped
    return api(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/elastic_enterprise_search/_sync/client/app_search.py", line 2384, in search
    return self.perform_request(  # type: ignore[return-value]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/elastic_enterprise_search/_sync/client/_base.py", line 249, in perform_request
    raise _HTTP_EXCEPTIONS.get(resp.meta.status, ApiError)(
elastic_enterprise_search.exceptions.BadRequestError: [400] {'errors': ['Options contains invalid key: boost']}
>>> 

With this change, the bug is resolved and AppSearch WAI.

>>> boosts = {
...     "num_interactions": [
...         {
...             "type": "functional",
...             "function": "logarithmic",
...             "operation": "add",
...             "factor": 3.5,
...         }
...     ]
... }
>>> 
>>> results2 = app_search_client.search(
...     engine_name=ENGINE, query=query, page_size=10, boost=boosts
... )
>>> len(results2['results'])
10

Maybe consider renaming the kwarg to boosts but hopefully in a follow up PR so I can be unblocked. Thank you!

@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@cla-checker-service
Copy link

cla-checker-service bot commented Oct 2, 2023

💚 CLA has been signed

@groeney groeney changed the title Add construct body with 'boosts' according to the current API Construct body with 'boosts' according to the current API Oct 2, 2023
@pquentin
Copy link
Member

pquentin commented Oct 7, 2023

Hello! I'm the new maintainer of the Elasticsearch Python clients.

Thanks for offering a pull request and sorry for the delay. It's slightly more complicated than merging the pull request because this code is generated and the generator no longer works properly. I will fix (worse case by just merging this) and release a new version next week.

Thank you for your patience.

@pquentin pquentin mentioned this pull request Oct 9, 2023
@pquentin
Copy link
Member

Hello! https://pypi.org/project/elastic-enterprise-search/8.10.0/ is out with this change and a few others. Sorry for the delay, this project had been essentially unmaintained for more than a year, so it took time to fix the CI and code generation. Hopefully it's in good hands now. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants