this should be obvious to me but is not. The following two-match only the second phase (in this case, Cape Basin
)
"query": { "match_phrase": { "contents": { "query": "St Peter Fm", "query": "Cape Basin" } } } "query": { "match_phrase": { "contents": { "query": ["St Peter Fm", "Cape Basin"] } } }
while the following croaks with an error
"query": { "match_phrase": { "contents": { "query": "St Peter Fm" }, "contents": { "query": "Cape Basin" } } }
I want to match all documents that contain either phrases exactly as entered.
Match phrase queryeditA phrase query matches terms up to a configurable slop (which defaults to 0) in any order. Transposed terms have a slop of 2. The analyzer can be set to control which analyzer will perform the analysis process on the text.
The multi_match query builds on the match query to allow multi-field queries: GET /_search { "query": { "multi_match" : { "query": "this is a test", "fields": [ "subject", "message" ] } } } The query string. The fields to be queried.
The match query analyzes any provided text before performing a search. This means the match query can search text fields for analyzed tokens rather than an exact term. (Optional, string) Analyzer used to convert the text in the query value into tokens. Defaults to the index-time analyzer mapped for the <field> .
You need to use the bool query to combine different queries together. You can then choose whether each single query must match, should match (optional), or must not match.
Your first query is not really a valid JSON object because you use the same field name twice.
You can use a bool must query to match both phrases:
PUT phrase/doc/1 { "text": "St Peter Fm some other text Cape Basin" } GET phrase/_search { "query": { "bool": { "must": [ {"match_phrase": {"text": "St Peter Fm"}}, {"match_phrase": {"text": "Cape Basin"}} ] } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With