0

I have a schema that allows a multivalued field, how do I construct a search that only returns documents that have 2 or more entries in that field? for example in this subset of data:

<doc>
<str name="id">A</str>
<arr name="multivaluedField">
  <str>One</str>
  <str>Two</str>
</arr></doc>

<doc>
<str name="id">B</str>
<arr name="multivaluedField">
  <str>One</str>
</arr></doc>

<doc>
<str name="id">C</str>
<arr name="multivaluedField">
  <str>Three</str>
  <str>Four</str>
</arr></doc>

The search would return documents A and C only since they have 2 entries in MultivaluedField even if they are different entries.

Jorge Lazo
  • 388
  • 7
  • 18

1 Answers1

2

The easiest (and most effective) way would be to index a integer value that contains the count of values together with the existing values, so you have a multiValued_count field. This field can be indexed and you can do both efficient range queries and exact value lookups.

You can do this in your indexing code directly or in an updateprocessor if needed.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84