Does elastic support wildcard for fieldnames in sort filter

This is our sample document that is indexed

 {
                    "details": {
                        "orderID": "O1",
                        "createdon": "2019-02-23",
                        "status": "NEW"
                    },
                    "items": [
                        {
                            "orderID": "O1",
                            "orderLineID": "OL1_O1",
                        }
}

Does sort filter support wild card in field names ?

e.g.

http://localhost:9200/orders/details/_search -- POST

{
"sort" : [
{ "details.createdon": {"order":"asc"}}
]
}

This works

What we are looking for is some thing like wild card in fieldnames

{
"sort" : [
{ "\*createdon": {"order":"asc"}}
]
}

No, the field names don't support wildcards. Ordering needs to be deterministic; given the same sort order and the same set of documents, the results should sort the same. Adding wildcards to sort fields makes it unclear what order the sorting is applied.

E.g. a_createdon and 1_createdon would both match, but which order should they be applied? Even if the order of operations is documented, it's not clear to someone reading the query without checking the documentation.

Why do you want wildcards for field names? Do you have a very large number of fields you are trying to sort by?

1 Like

Our documents structure is fixed where the most popular sort key is by the createdon field. Now this field appear in different document categories like . i.e. order > details ; shipping > tracking etc

So, right now the calling app is required to send sort key as details.createdon or shippingtracking.createdon vs *createdon.

So was curious to see if sort filter also support wild card in field names the way the query filter supports

Ah, I see. Yeah unfortunately that's not possible right now, you'll have to enumerate out the sorts manually instead.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.