Match all terms in document array

I don't think there is really a simple and efficient way to solve the problem the way you have stated it. The basic data structure behind the search engine is inverted index, it's basically a map from tokens to documents that contain these tokens. So, it's easy to find all documents that contain certain token and it's easy to find documents that don't contain certain token, but it's difficult to find all document that contain only a subset of tokens. And you cannot change minimum should match on per-record bases.

I see 4 main approaches that you can use to solve this problem, but they all have certain drawbacks.

  1. Script-based approach. Your search will search for documents that contain any of the terms in your query and then use script filter to through away all documents that contain any of the terms that are not in the list of desired term. You can also combine with query with a query for an empty arr field.

  2. Searching for a complimentary set. Searching for all documents that don't contain any tokens that are not in your list. Basically in your example you search would be -arr:6 -arr:10 assuming that you only have 10 different terms in your index.

  3. Combinatoric expansion of the query. Basically, you index arr as a single token of sorted values (the first record would be sorted as 1-3-5). And then you expand your query into all possible subsets: 1, 2, 3, 4, 5, 1-2, 1-3, 1-4, 1-5, 2-3, 2-4, 2-5, 3-4, 3-5, 1-2-3, 1-2-4, 1-2-5, 1-3-4, 1-3-5, 1-4-5, 1-2-3-4, 1-2-3-5, 1-2-4-5, 1-3-4-5, 2-3-4-5, 1-2-3-4-5. This is the basic idea, but there several optimization that can be applied to reduce the huge combinatoric expansion.

  4. Using percolator. Basically your arrays become search queries and you convert your search query into a document that "searches" the queries.

Can you give more information about your problem and what you are actually trying to achieve? There are might be other simpler approaches that might result in even better user experience.