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

Query rules docs clarification #98605

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ The actions to take when the rule matches a query:
* `ids` will pin the specified <<mapping-id-field,`_id`>>s.
* `docs` will pin the specified documents in the specified indices.

Use `ids` when searching over a single index, and `docs` when searching over multiple indices. See <<query-dsl-pinned-query,pinned query>> for details.
Use `ids` when searching over a single index, and `docs` when searching over multiple indices.
`ids` and `docs` cannot be combined in the same query.
See <<query-dsl-pinned-query,pinned query>> for details.

[discrete]
[[add-query-rules]]
Expand All @@ -105,8 +107,8 @@ You can add query rules using the <<put-query-ruleset>> call. This adds a rulese

The following command will create a query ruleset called `my-ruleset` with two pinned document rules:

* The first rule will generate a <<query-dsl-pinned-query>> pinning the <<mapping-id-field,`_id`>>s `id1` and `id2` when the `user.query` metadata value is a fuzzy match to either `puggles` or `pugs` _and_ the user's location is in the US.
* The second rule will generate a <<query-dsl-pinned-query>> pinning the <<mapping-id-field, `_id`>> of `id3` specifically from the `my-index-000001` index and `id4` from the `my-index-000002` index when the `user.query` metadata value matches `beagles`.
* The first rule will generate a <<query-dsl-pinned-query>> pinning the <<mapping-id-field,`_id`>>s `id1` and `id2` when the `user_query` metadata value is a fuzzy match to either `puggles` or `pugs` _and_ the user's location is in the US.
Copy link
Contributor

Choose a reason for hiding this comment

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

@kderusso I don't see user_query anywhere in the example that follows. Maybe it's my ignorance of query rules - is it an implicit metadata field? Or did you mean to refer to query_string?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, changing to query_string

kderusso marked this conversation as resolved.
Show resolved Hide resolved
* The second rule will generate a <<query-dsl-pinned-query>> pinning the <<mapping-id-field, `_id`>> of `id3` specifically from the `my-index-000001` index and `id4` from the `my-index-000002` index when the `user_query` metadata value contains `beagles`.
kderusso marked this conversation as resolved.
Show resolved Hide resolved

////
[source,console]
Expand All @@ -132,7 +134,7 @@ PUT /_query_rules/my-ruleset
},
{
"type": "exact",
"metadata": "user.country",
"metadata": "user_country",
"values": [ "us" ]
}
],
Expand Down Expand Up @@ -204,7 +206,7 @@ GET /my-index-000001/_search
},
"match_criteria": {
"query_string": "puggles",
"user.country": "us"
"user_country": "us"
},
"ruleset_id": "my-ruleset"
}
Expand All @@ -214,4 +216,4 @@ GET /my-index-000001/_search
// TEST[continued]

This rule query will match against `rule1` in the defined query ruleset, and will convert the organic query into a pinned query with `id1` and `id2` pinned as the top hits.
Any other matches from the `user.query` query specified in the organic query will be returned below the pinned results.
Any other matches from the organic query will be returned below the pinned results.