Hii,
I tried a lot of queries.. but, Its not works.. It through an error.. Can anyone try this
Here is my mapping,
PUT array_sort
{
"mappings": {
"properties": {
"Skills": {
"type": "nested",
"properties": {
"text": {
"type": "keyword"
}
}
}
}
}
}
This is the data
POST array_sort/_doc/1
{
"Skills": [
{"text": "java"},
{"text": "elasticsearch"}
]
}
POST array_sort/_doc/2
{
"Skills": [
{"text": "python"},
{"text": "ruby"},
{"text": "javascript"}
]
}
POST array_sort/_doc/3
{
"Skills": [
{"text": "sql"},
{"text": "html"},
{"text": "css"}
]
}
Here is the query for finding that array size more then two,
GET array_sort/_search
{
"query": {
"nested": {
"path": "Skills",
"query": {
"script": {
"script": {
"source": "doc['Skills'].length > 3",
"lang": "painless"
}
}
}
}
}
}
I tried a lot of queries But, I am getting an error.. Here is an error
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.server@8.7.1/org.elasticsearch.search.lookup.LeafDocLookup.getFactoryForDoc(LeafDocLookup.java:127)",
"org.elasticsearch.server@8.7.1/org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:170)",
"org.elasticsearch.server@8.7.1/org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:32)",
"""if (doc['Skills'].length() > 2) {
""",
" ^---- HERE"
],
"script": " ...",
"lang": "painless",
"position": {
"offset": 23,
"start": 15,
"end": 65
}
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "array_sort",
"node": "x4tf2IsOSUu4VVsm2zVwGA",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.server@8.7.1/org.elasticsearch.search.lookup.LeafDocLookup.getFactoryForDoc(LeafDocLookup.java:127)",
"org.elasticsearch.server@8.7.1/org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:170)",
"org.elasticsearch.server@8.7.1/org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:32)",
"""if (doc['Skills'].length() > 2) {
""",
" ^---- HERE"
],
"script": " ...",
"lang": "painless",
"position": {
"offset": 23,
"start": 15,
"end": 65
},
"caused_by": {
"type": "illegal_argument_exception",
"reason": "No field found for [Skills] in mapping"
}
}
}
]
},
"status": 400
}
Can you anyone try this and inform.. Why I am encountering this Error. If you find anything let me know.
Thank you,