Exact phrase matching in any word order, but restricts words not in query

I would like to query for 'apple pie' and return the result 'apple pie' as
well as 'pie apple', but I want to restrict any results such as 'apple pie
crumb cake' or 'brown apple pie'. Is there some kind of: 'result must
match query exactly' or some way to use the score as an indicator for a
perfect/exact match?

Default operator 'and' is perfect, but it also retrieves results that do
not match exactly.

'not_analyze' or tokenizing the fields as 'keyword' doesn't allow me to
query for the item in reverse, ie: 'apple pie' works, but 'pie apple' does
not.

Is the solution to tokenize the input such that each permutation of the
string is indexed as a keyword? ie- 'apple pie crumb cake' as:
'apple cake pie crumb'
'apple cake crumb pie'
etc.

or is there a way to filter queries such that they only return results that
match every word in the query and rejects results that contain excess words
not found in the original query? ie - 'exact_match': 'true'

Wayne

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Wayne,

This is why I use the Java API and not the REST API. Using Java, I can more
easily pre-process the search to construct the proper query, and then I can
much more easily pre-process the responses to handle cases such as yours,
or for a very smooth and nice multi-field hierarchical facet response
(which is not in ES currently, but my add-on isn't "hacky at all!).

In your case, you could analyze your search term. Then, for each search hit
you could analyze the response field. If the search hit doesn't analyze to
the same number of terms that the search had, you would throw away
("filter") that match. That would give you an exact match as you describe.

Good luck!
Brian

On Wednesday, July 17, 2013 8:47:25 AM UTC-4, Wayne Yang wrote:

I would like to query for 'apple pie' and return the result 'apple pie' as
well as 'pie apple', but I want to restrict any results such as 'apple pie
crumb cake' or 'brown apple pie'. Is there some kind of: 'result must
match query exactly' or some way to use the score as an indicator for a
perfect/exact match?

Default operator 'and' is perfect, but it also retrieves results that do
not match exactly.

'not_analyze' or tokenizing the fields as 'keyword' doesn't allow me to
query for the item in reverse, ie: 'apple pie' works, but 'pie apple' does
not.

Is the solution to tokenize the input such that each permutation of the
string is indexed as a keyword? ie- 'apple pie crumb cake' as:
'apple cake pie crumb'
'apple cake crumb pie'
etc.

or is there a way to filter queries such that they only return results
that match every word in the query and rejects results that contain excess
words not found in the original query? ie - 'exact_match': 'true'

Wayne

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

One solution would be to calculate number of words in your document and store it as a field. Then count number of qords in your query and add count equality to your query.

To be consistent you would need to use analyzer to count number of terms in your document and store it and the same analyzer in your query and to count terms in your phrase

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.