pjanzen
(Paul Janzen)
January 8, 2018, 11:46am
1
Hi all,
So I am trying to compare two fields from a specific progam. I am trying it with this.
{
"query": {
"bool": {
"must": [{
"script": {
"script": {
"inline": "doc['email.keyword'].value == params.param1",
"lang": "painless",
"params": {
"param1": "doc['redirect.keyword'].value"
}
}
},
"match": {
"program": "get_forwarding_address"
}
}]
}
}
}
However I am still getting the following error.
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[script] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 14,
"col": 9
}
],
"type": "parsing_exception",
"reason": "[script] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 14,
"col": 9
},
"status": 400
}
Could someone please advice on how to correctly setup this query?
Thanks,
Paul.
val
(Val Crettaz)
January 8, 2018, 11:51am
2
In the parameters section, you cannot reference a field from the document.
Why not simply doing this?
"script": {
"inline": "doc['email.keyword'].value == doc['redirect.keyword'].value",
"lang": "painless",
"params": {
}
}
1 Like
pjanzen
(Paul Janzen)
January 8, 2018, 11:55am
3
That still produces the same error:
"type": "parsing_exception",
"reason": "[script] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 14,
"col": 9
val
(Val Crettaz)
January 8, 2018, 11:57am
4
If you're using ES 6, you need to replace inline
by source
. Could that be the reason?
1 Like
pjanzen
(Paul Janzen)
January 8, 2018, 12:00pm
5
Sorry, I must have stated that in the intro, I am using ES 5
colings86
(Colin Goodheart-Smithe)
January 8, 2018, 12:00pm
6
You can only put one query in each must clause in the must array, you need to separate your script and match queries into separate objects. However the replies by @val are also true and you would have reached those issues next I suspect.
Try this:
{
"query": {
"bool": {
"must": [
{
"script": {
"script": {
"source": "doc['email.keyword'].value == doc['redirect.keyword'].value",
"lang": "painless"
}
}
},
{
"match": {
"program": "get_forwarding_address"
}
}
]
}
}
}
1 Like
pjanzen
(Paul Janzen)
January 8, 2018, 12:10pm
8
Thanks for the help all,
I have now this and it does exactly what I want
{
"_source": [
"email"
],
"query": {
"bool": {
"must": [
{
"script": {
"script": {
"inline": "doc['email.keyword'].value == doc['redirect.keyword'].value",
"lang": "painless"
}
}
},
{
"match": {
"program": "get_forwarding_address"
}
}
]
}
}
}
system
(system)
Closed
February 5, 2018, 12:10pm
9
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.