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

Categorize search queries by type and log query shape #10724

Merged
merged 35 commits into from
Oct 19, 2023

Conversation

deshsidd
Copy link
Contributor

Description
Changes to categorize search queries based on the type of the query (eg: bool, match, multi-match, etc).
Changes also log the query shape of a query (queries can have a nested structure with a hierarchy of subqueries).

Use QueryShapeVisitor to debug log the shape of the queries. Example
Use QueryBuilderVisitor to visit all the nodes of the querybuilder tree for incoming search queries and increment counters to capture query type information
Integrate with #10241 for the counters
Related Issues
Resolves #10250

Check List
New functionality includes testing.
All tests pass
New functionality has been documented.
New functionality has javadoc added
Commits are signed per the DCO using --signoff
Commit changes are listed out in CHANGELOG.md file (See: Changelog)
Public documentation issue/PR created
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Previous PR with comments : #10502

@github-actions
Copy link
Contributor

github-actions bot commented Oct 19, 2023

Compatibility status:

Checks if related components are compatible with change b172450

Incompatible components

Skipped components

Compatible components

Compatible components: [https://github.com/opensearch-project/security.git, https://github.com/opensearch-project/alerting.git, https://github.com/opensearch-project/index-management.git, https://github.com/opensearch-project/anomaly-detection.git, https://github.com/opensearch-project/sql.git, https://github.com/opensearch-project/job-scheduler.git, https://github.com/opensearch-project/asynchronous-search.git, https://github.com/opensearch-project/common-utils.git, https://github.com/opensearch-project/observability.git, https://github.com/opensearch-project/k-nn.git, https://github.com/opensearch-project/reporting.git, https://github.com/opensearch-project/security-analytics.git, https://github.com/opensearch-project/custom-codecs.git, https://github.com/opensearch-project/cross-cluster-replication.git, https://github.com/opensearch-project/opensearch-oci-object-storage.git, https://github.com/opensearch-project/performance-analyzer.git, https://github.com/opensearch-project/ml-commons.git, https://github.com/opensearch-project/performance-analyzer-rca.git, https://github.com/opensearch-project/geospatial.git, https://github.com/opensearch-project/notifications.git, https://github.com/opensearch-project/neural-search.git]

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

deshsidd and others added 20 commits October 19, 2023 13:37
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Michael Froh <[email protected]>
Signed-off-by: Siddhant Deshmukh <[email protected]>
@deshsidd deshsidd force-pushed the sid/search-query-category-final branch from f3194f1 to b172450 Compare October 19, 2023 20:37
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT: UNSTABLE ❕
  • TEST FAILURES:
      1 org.opensearch.search.SearchWeightedRoutingIT.testMultiGetWithNetworkDisruption_FailOpenEnabled
      1 org.opensearch.index.IndexServiceTests.testAsyncTranslogTrimTaskOnClosedIndex

@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

Merging #10724 (b172450) into main (69f6f4e) will decrease coverage by 0.07%.
Report is 2 commits behind head on main.
The diff coverage is 90.13%.

@@             Coverage Diff              @@
##               main   #10724      +/-   ##
============================================
- Coverage     71.11%   71.04%   -0.07%     
+ Complexity    58530    58484      -46     
============================================
  Files          4854     4858       +4     
  Lines        276049   276178     +129     
  Branches      40168    40184      +16     
============================================
- Hits         196311   196221      -90     
- Misses        63385    63532     +147     
- Partials      16353    16425      +72     
Files Coverage Δ
.../action/search/SearchQueryCategorizingVisitor.java 100.00% <100.00%> (ø)
.../opensearch/action/search/SearchQueryCounters.java 100.00% <100.00%> (ø)
...rg/opensearch/common/settings/ClusterSettings.java 92.85% <ø> (ø)
...search/index/shard/RemoteStoreRefreshListener.java 87.50% <100.00%> (+1.40%) ⬆️
...ensearch/action/search/SearchQueryCategorizer.java 96.77% <96.77%> (ø)
...in/java/org/opensearch/index/shard/IndexShard.java 69.29% <94.44%> (-0.13%) ⬇️
.../org/opensearch/index/query/QueryShapeVisitor.java 94.73% <94.73%> (ø)
...ain/java/org/opensearch/search/DocValueFormat.java 59.17% <0.00%> (-5.33%) ⬇️
...pensearch/action/search/TransportSearchAction.java 67.95% <42.85%> (-0.90%) ⬇️

... and 455 files with indirect coverage changes

@mch2 mch2 merged commit 781968b into opensearch-project:main Oct 19, 2023
16 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-2.x
# Create a new branch
git switch --create backport/backport-10724-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 781968b2e53f3214b73d4d8e7c1baa572b334f27
# Push it to GitHub
git push --set-upstream origin backport/backport-10724-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-10724-to-2.x.

austintlee pushed a commit to austintlee/OpenSearch that referenced this pull request Oct 23, 2023
…ject#10724)

* Search Query Categorizor initial skeleton using QueryBuilderVisitor

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Integrate metrics framework, add counters and log query shape

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Update changelog

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Add level attribute to QueryBuilderVisitor and as a tag in Counters

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Log query shape as debug log

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Integrate metrics framework, refactor code and update tests

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Fix build

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Add javadocs

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Minor fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Spotless check changes

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Address comments, add agg and sort counters, add feature flag, refactoring

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Build fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* spotless check

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Fix tests

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Dynamic feature flag with callback

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Minor fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Add initialization in callback

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Address comments

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Add exception handling

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Refactoring and renaming

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Minor fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Fix changelog and minor refactoring

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Address review comments

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Add unit tests

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Address review comments and add complex query unit test

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Add sort order as a tag to sort counter

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Address review comments

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Address final comments

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Build fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Fix build tests failure

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Minor fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Minor fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Empty commit

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Remove extra newline

Signed-off-by: Michael Froh <[email protected]>

* Empty commit

Signed-off-by: Siddhant Deshmukh <[email protected]>

---------

Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Michael Froh <[email protected]>
Co-authored-by: Michael Froh <[email protected]>
shiv0408 pushed a commit to Gaurav614/OpenSearch that referenced this pull request Apr 25, 2024
…ject#10724)

* Search Query Categorizor initial skeleton using QueryBuilderVisitor

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Integrate metrics framework, add counters and log query shape

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Update changelog

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Add level attribute to QueryBuilderVisitor and as a tag in Counters

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Log query shape as debug log

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Integrate metrics framework, refactor code and update tests

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Fix build

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Add javadocs

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Minor fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Spotless check changes

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Address comments, add agg and sort counters, add feature flag, refactoring

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Build fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* spotless check

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Fix tests

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Dynamic feature flag with callback

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Minor fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Add initialization in callback

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Address comments

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Add exception handling

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Refactoring and renaming

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Minor fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Fix changelog and minor refactoring

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Address review comments

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Add unit tests

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Address review comments and add complex query unit test

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Add sort order as a tag to sort counter

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Address review comments

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Address final comments

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Build fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Fix build tests failure

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Minor fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Minor fix

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Empty commit

Signed-off-by: Siddhant Deshmukh <[email protected]>

* Remove extra newline

Signed-off-by: Michael Froh <[email protected]>

* Empty commit

Signed-off-by: Siddhant Deshmukh <[email protected]>

---------

Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: Michael Froh <[email protected]>
Co-authored-by: Michael Froh <[email protected]>
Signed-off-by: Shivansh Arora <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch backport-failed enhancement Enhancement or improvement to existing feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search Query Categorization (Phase 1)
7 participants