Query for the fields which is non empty

Hi Team,
I'm reaching out query that I have, I want a query which returns the field with any random value inside it and filter out the empty records.

For eg: In my case, I have a FileContent.content field and it has values for that field and few doesn't have any value for it and it is empty. I figured out the query to filter out the empty values l, but I want a query which gives me the Filecontent.content field which has values in it. I've been trying alot on this. Can someone please help on this?

Here is the query I tried for filtering out the empty values :
{
"query": {
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"exists": {
"field": "FileContent.content"
}
}
]
}
},
{
"term": {
"FileContent.content": ""
}
}
]
}
}
}

The above query is working perfectly fine for empty records, but I need a query which gives me the FileContent.content with a value inside it i.e; non empty.

Can you please help me on this?
I've been stuck since a long time.

Thanks in advance and appreciate you if you can really help me on this.

Hi @Manasa4

The query below works?

{
  "query": {
    "bool": {
      "must_not": [
        {
          "term": {
            "FileContent.content": ""
          }
        }
      ]
    }
  }
}

Yes! I did try this and this is giving me the whole index count. It would be really be helpful if you can give me the query for the non empty fields.

Thanks,
Manasa

If I follow you need somthing like this:

{
    "query": {
        "bool": {
            "must": [
                {
                    "exists": {
                        "field": "FileContent.content"
                    }
                }
            ],
            "must_not": [
                {
                  "term": {
                    "FileContent.content": ""
                  }
                }
            ]
        }
    }
}

This query makes sure the field exists and that the field is not 'empty'.

1 Like

Hi sholzhauer,

Thanks for the input. But the above query is giving the empty records. This query is working perfectly for non-empty records :
{"query": {
"bool": {
"must": {
"exists": {
"field": "Description"
}
},
"must_not": {
"term": {
"Description.keyword": ""
}
}
}
}
}

The above query eliminates all the empty records and process only non-empty records

I am afraid I don't understand what you need then?

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