Is there a way to sort by the existance of a specific field?

(Gerald DeConto) #1

say I have a field that may or may not exist for a given document (ie if there is no data, the field would not get created during data population)

is there a fast way to sort by the existence of that field (basically a boolean sort)? ie all document where that field exist are at the top of the results, followed by all documents where the field doesnt exist?

If the field were a string, know that I could sort by the content of that field, but a string sort would, I imagine, be slower than just checking to see if the field exists.

if the field was a node that might contain other fields (which may or may not exist), we could sort by the content of a subfield, but the subfields too might or might not exist.

the last resort would probably be to add a boolean field to the schema that would indicate whether or not data for that field exists when the document is populated.

any thoughts appreciated

(Gerald DeConto) #2

note that I found one way to do this:

"sort": [
"node1.node1a.field1": {"missing" : "_last"}

(system) #3