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

[BUG] Issue with percolate query transforming documents with object type fields #844

Closed
eirsep opened this issue Mar 30, 2023 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@eirsep
Copy link
Member

eirsep commented Mar 30, 2023

Mapping

{
  "mappings": {
    "properties": {
      "something.a.b": { "type": "long" }
    }
  }
}

Document that the monitor is not able to recognize but the index ingests correctly based on. the mapping

{
    "something": {
        "a" : {
            "b" : 123
        }
    }
}

Document that the monitor is able to recognize and trigger

{
    "something.a.b" : 123
}

Doc-level monitor spec

{
						"type": "monitor",
						"schema_version": 1,
						"name": "test",
						"monitor_type": "doc_level_monitor",
						"enabled": true,
						"enabled_time": 1680126087150,
						"schedule": {
							"period": {
								"interval": 1,
								"unit": "MINUTES"
							}
						},
						"inputs": [{
							"doc_level_input": {
								"description": "test",
								"indices": [
									"i3"
								],
								"queries": [{

										"name": "78b3756a-7804-4ef7-8555-7b9024a02d2d",
										"query": "(something.a.b:123)",
										"tags": [
											"low",
											"cloudtrail",
											"attack.exfiltration",
											"attack.t1537"
										]
									}
								]
							}
						}],
						"triggers": [{
							"document_level_trigger": {
								"id": "FY5RL4cBirpptBbLj0ju",
								"name": "CW Trail Alert",
								"severity": "1",
								"condition": {
									"script": {
										"source": "(query[tag=cloudtrail])",
										"lang": "painless"
									}
								}
							}
						}]
					
					}
@eirsep eirsep added the bug Something isn't working label Mar 30, 2023
@eirsep
Copy link
Member Author

eirsep commented Mar 30, 2023

We need to consciously handle transformation logic for null values and array type values also

@eirsep eirsep removed the untriaged label Mar 30, 2023
@eirsep
Copy link
Member Author

eirsep commented Mar 30, 2023

Field transform logic at needs to be fixed

return hits.map { hit ->
val sourceMap = hit.sourceAsMap
var xContentBuilder = XContentFactory.jsonBuilder().startObject()
sourceMap.forEach { (k, v) ->
xContentBuilder = xContentBuilder.field("${k}_${index}_$monitorId", v)
}
xContentBuilder = xContentBuilder.endObject()
val sourceRef = BytesReference.bytes(xContentBuilder)
Pair(hit.id, sourceRef)
}

@lezzago
Copy link
Member

lezzago commented Apr 6, 2023

PR has been merged, but backports failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants