Skip to content

How to Search For Empty Fields #107

Closed
@Aleck-Sun

Description

@Aleck-Sun

Hi, I've been trying to create a query that searches for documents that have an empty field. Currently, when creating the index I am just setting a documents' empty fields to a specific keyword like "EMPTYBLUGEFIELD" and creating a query for it. I was wondering if there was a more proper way to perform this search?

What I've been doing:
When creating index:

If field != "" {
	doc.AddField(bluge.NewKeywordField("Field", "FieldValue").StoreValue())
} else {
        doc.AddField(bluge.NewKeywordField("Field", "EMPTYBLUGEFIELD").StoreValue())
}

When searching:

query.AddShould(bluge.NewTermQuery("FieldValue").SetField("Field"))
query.AddShould(bluge.NewTermQuery("EMPTYBLUGEFIELD").SetField("Field"))
query.SetMinShould(1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions