-
Notifications
You must be signed in to change notification settings - Fork 108
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
Fixed transformation of document field names before running percolator search #845
Fixed transformation of document field names before running percolator search #845
Conversation
…r search Signed-off-by: Petar Dzepina <[email protected]>
Signed-off-by: Petar Dzepina <[email protected]>
… of outputing flatten json Signed-off-by: Petar Dzepina <[email protected]>
Signed-off-by: Petar Dzepina <[email protected]>
alerting/src/test/kotlin/org/opensearch/alerting/MonitorDataSourcesIT.kt
Outdated
Show resolved
Hide resolved
alerting/src/test/kotlin/org/opensearch/alerting/MonitorDataSourcesIT.kt
Show resolved
Hide resolved
alerting/src/test/kotlin/org/opensearch/alerting/MonitorDataSourcesIT.kt
Show resolved
Hide resolved
|
||
val sourceRef = BytesReference.bytes(xContentBuilder) | ||
|
||
Pair(hit.id, sourceRef) | ||
} | ||
} | ||
|
||
/** | ||
* Traverses document fields in leaves recursively and appends [fieldNameSuffix] to field names. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mention that we are trying to flatten the object type fields for percolate query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we can't flatten it, because of type=nested. You can't insert document with flatten fields if type is nested. For example, let's say field "rule" is type=nested, then this is invalid:
{
"rule.category": "windows"
}
but this is valid:
{
"rule" : {
"category": "windows"
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am not talking about type=nested
* @param jsonAsMap Input JSON (as Map) | ||
* @param fieldNameSuffix Field suffix which is appended to existing field name | ||
*/ | ||
private fun transformDocumentFieldNames( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if customer has a nested type mapping for the index.
plz add a test case to verify we are handling that and fix it if required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a test case with document with nested fields: "test execute monitor with custom query index and nested mappings"
if (entry.value is Map<*, *>) { | ||
transformDocumentFieldNames(entry.value as MutableMap<String, Any>, fieldNameSuffix) | ||
} else if (entry.key.endsWith(fieldNameSuffix) == false) { | ||
tempMap["${entry.key}_$fieldNameSuffix"] = entry.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add debug logs with field name generated and mention percolate query stage, monitor id
we are lacking insights into what is going wrong
this might help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added trace log here printing whole document
alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this important fix Petar,
added a few comments reg. testing, logging and verbose comments/documentation
Signed-off-by: Petar Dzepina <[email protected]>
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #845 +/- ##
============================================
+ Coverage 75.46% 75.55% +0.09%
+ Complexity 111 110 -1
============================================
Files 125 125
Lines 6885 6886 +1
Branches 1034 1036 +2
============================================
+ Hits 5196 5203 +7
+ Misses 1158 1154 -4
+ Partials 531 529 -2
... and 8 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Signed-off-by: Petar Dzepina <[email protected]>
alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt
Outdated
Show resolved
Hide resolved
* | ||
* Example for index name is my_log_index and Monitor ID is TReewWdsf2gdJFV: | ||
* { { | ||
* "a": { "a": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not want a
to be appended with my_log_index_TReewWdsf2gdJFV
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't, since we transform mappings in the same way
alerting/src/test/kotlin/org/opensearch/alerting/MonitorDataSourcesIT.kt
Show resolved
Hide resolved
Signed-off-by: Petar Dzepina <[email protected]>
while (it.hasNext()) { | ||
val entry = it.next() | ||
if (entry.value is Map<*, *>) { | ||
transformDocumentFieldNames(entry.value as MutableMap<String, Any>, fieldNameSuffix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unchecked type cast happens here. please use @Suppress("UNCHECKED_CAST")
val entry = it.next() | ||
if (entry.value is Map<*, *>) { | ||
transformDocumentFieldNames(entry.value as MutableMap<String, Any>, fieldNameSuffix) | ||
} else if (entry.key.endsWith(fieldNameSuffix) == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also make it !entry.key.endsWith(fieldNameSuffix)
the pr looks good. |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-845-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 702da92495481bebfc18dbee2de9544a4245759a
# Push it to GitHub
git push --set-upstream origin backport/backport-845-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x Then, create a pull request where the |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.3 2.3
# Navigate to the new working tree
cd .worktrees/backport-2.3
# Create a new branch
git switch --create backport/backport-845-to-2.3
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 702da92495481bebfc18dbee2de9544a4245759a
# Push it to GitHub
git push --set-upstream origin backport/backport-845-to-2.3
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.3 Then, create a pull request where the |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.4 2.4
# Navigate to the new working tree
cd .worktrees/backport-2.4
# Create a new branch
git switch --create backport/backport-845-to-2.4
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 702da92495481bebfc18dbee2de9544a4245759a
# Push it to GitHub
git push --set-upstream origin backport/backport-845-to-2.4
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.4 Then, create a pull request where the |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.5 2.5
# Navigate to the new working tree
cd .worktrees/backport-2.5
# Create a new branch
git switch --create backport/backport-845-to-2.5
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 702da92495481bebfc18dbee2de9544a4245759a
# Push it to GitHub
git push --set-upstream origin backport/backport-845-to-2.5
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.5 Then, create a pull request where the |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.6 2.6
# Navigate to the new working tree
cd .worktrees/backport-2.6
# Create a new branch
git switch --create backport/backport-845-to-2.6
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 702da92495481bebfc18dbee2de9544a4245759a
# Push it to GitHub
git push --set-upstream origin backport/backport-845-to-2.6
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.6 Then, create a pull request where the |
…r search (opensearch-project#845) * Fixed transformation of document field names before running percolator search Signed-off-by: Petar Dzepina <[email protected]> (cherry picked from commit 702da92)
* Fixed transformation of document field names before running percolator search (#845) * Fixed transformation of document field names before running percolator search Signed-off-by: Petar Dzepina <[email protected]> (cherry picked from commit 702da92) * fixed module class names Signed-off-by: Petar Dzepina <[email protected]> --------- Signed-off-by: Petar Dzepina <[email protected]>
Issue #, if available: #844
Description of changes:
Fixed transformation of document field names before running percolator search.
Documents which are ingested with "nested fields" weren't handled properly. Example:
CheckList:
[ ] Commits are signed per the DCO using --signoff
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.