Skip to content

Add Synonyms and Query rules APIs #2299

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

Merged
merged 4 commits into from
Sep 21, 2023

Conversation

pquentin
Copy link
Member

@pquentin pquentin commented Sep 14, 2023

Closes #2288

The first commit applies generation and nox -rs format, while the second one contains my manual fixes. Tested as follows:

from elasticsearch import Elasticsearch

# Start with `docker run -p 9200:9200 -it -e xpack.security.enabled=false -e discovery.type=single-node docker.elastic.co/elasticsearch/elasticsearch:8.10.0-SNAPSHOT`
es = Elasticsearch("http://localhost:9200")


es.synonyms.put_synonym(
    id="my-synonyms-set",
    synonyms_set=[
        {"id": "test-1", "synonyms": "hello, hi"},
        {"synonyms": "bye, goodbye"},
        {"id": "test-2", "synonyms": "test => check"},
    ],
)
print(es.synonyms.get_synonyms_sets())

es.query_ruleset.put(
    ruleset_id="my-ruleset",
    query_ruleset={
        "rules": [
            {
                "rule_id": "my-rule1",
                "type": "pinned",
                "criteria": [
                    {
                        "type": "contains",
                        "metadata": "user.query",
                        "values": ["marvel", "dc"],
                    },
                    {"type": "exact", "metadata": "user.country", "values": ["us"]},
                ],
                "actions": {"ids": ["id1", "id2"]},
            }
        ]
    },
)
print(es.query_ruleset.list())

Note that es.query_ruleset.put is weird, I would have expected to be able to use es.query_ruleset.put(ruleset_id="my-ruleset", rules=[...]) instead as is idiomatic for the 8.x client. Any thoughts on that @kderusso?

@kderusso
Copy link
Member

@pquentin Thanks for adding this. This is odd, I can put in an issue to improve it for 8.11. There may already be other client updates to go along with it as it's in tech preview.

@pquentin
Copy link
Member Author

This issue was supposed to be fixed by elastic/elasticsearch-specification#2242 but @Anaethelion is also seeing the same issue in Go, which likely means we need an additional fix in elasticsearch-specification.

@kderusso
Copy link
Member

Thanks @pquentin. I think this should resolve it? elastic/elasticsearch-specification#2276

@JoshMock
Copy link
Member

Was DMing with @pquentin about this, figured I'd put it on the PR itself to register my confusion openly. 😆

What is the difference between 9965478 and 5abe9cf? Both have the same exact number of lines changed, but they differ in ways that are hard to see immediately, mostly because it's so many lines changed. Also: is @pquentin a high-performing genius that he was able to modify thousands of lines of code in a relatively short period of time?

@JoshMock
Copy link
Member

Never mind. Github is apparently lying to me today. 😱 I have reloaded those diffs in my browser multiple times and suddenly, just now, the diffs changed completely. I may be going crazy.

JoshMock
JoshMock previously approved these changes Sep 18, 2023
@JoshMock
Copy link
Member

New day, brain is working properly. Thanks for fixing this. Once it's merged, we can publish 8.10 to PyPI.

Can you make sure the fix gets merged to the generator as well?

@pquentin
Copy link
Member Author

@kderusso With your fix, I can now write the following code:

es.query_ruleset.put(
    ruleset_id="my-ruleset",
    rules={
        "rule_id": "my-rule1",
        "type": "pinned",
        "criteria": [
            {
                "type": "contains",
                "metadata": "user.query",
                "values": ["marvel", "dc"],
            },
            {"type": "exact", "metadata": "user.country", "values": ["us"]},
        ],
        "actions": {"ids": ["id1", "id2"]},
    },
)

Thanks!

Copy link
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making this fix!

@pquentin pquentin merged commit f250598 into elastic:main Sep 21, 2023
@pquentin pquentin deleted the synonyms-queryruleset-codegen branch September 21, 2023 05:48
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.

Add synonyms and query rules APIs
3 participants