Phrase query on not analyzed field not working

122 views Asked by At

I have a product search index with a field "productOptions", that contains serialized JSON, meaning it may contain either an empty array for products with no options, or an array with options for products with product options:

  • []
  • [{ optionId: "", ... }]

When I try the query +productOptions: "[]" in Luke (using the StandardAnalyzer) I don't get any matches. I was under the impression that StandardAnalyzer will search not analyzed fields as long as there is an exact match - so I don't understand why I'm not getting any hits. However, if I switch over to KeywordAnalyzer I do get hits, but can't use KeywordAnalyzer since I'm querying product options as part of a more complex search query that requires StandardAnalyzer.

How can I write a query that finds all products with no options (i.e. productOptions == [])?

Note: I have no control over the indexing process, so I can't control the values being indexed.

1

There are 1 answers

2
Mysterion On

The problem here is the following, StandardAnalyzer effectively removes [] and leave this field with just empty string.

This makes searching later the same string [] - impossible to find anything.

One of the possibilities to achieve finding those “empty” strings is to search for -field_name:[* TO *], which means the following:

field_name:[* TO *] is a hacky workaround to search for any documents which contains anything but empty in this field and - is effectively negating this condition and ultimately asking for all documents which contains empty data in the field_name