1

im using QueryContainerDescriptor to fill a filter. i want to get all the document that their description is not equal to String.Empty.

i tried to do :

        public static QueryContainerDescriptor<T> FilterSummaryEmpty<T>(this QueryContainerDescriptor<T> qd)
where T : ElasticEntityDoc
        {           
            qd.Bool(b=> 
                        b.MustNot(mn =>                        
                            mn.Term(f => f.Description, string.Empty)
                        ));

            return qd;
        }

but its not working.

Also i tried to use regex for it but without success. what i'm doing wrong?

Elior Sastiel
  • 1,074
  • 2
  • 10
  • 21

1 Answers1

1

If you are using standard analyser, checking empty will not work because it will not be analysed as it is empty. So there won't be nothing as empty in the index to match for.

To check this, you need to make copy of the field in another field as not_analyzed in your mapping. Reference So you can check empty on copied field and other queries on description field.

There is one more way of checking that. You can use exists

While a field is deemed non-existent if the JSON value is null or [], these values will indicate the field does exist:

Empty strings, such as "" or "-" Arrays containing null and another value, such as [null, "foo"] A custom null-value, defined in field mapping

Gibbs
  • 21,904
  • 13
  • 74
  • 138