Open matt360-biz opened 7 years ago
For the _all it depends on your index mapping.
For the above you should probably set minimum_should_match
: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html Does it work if you use must
for only the content?
What should be the correct query to be able to search a term in in all fields, including document contents (attachments_content field)?
I was using this query, and it was able to search the term in titles of pages, content of pages and titles of documents. However it was not able to return results that had the search term in the contents of the documents. I thought using the '_all' would search all available fields including the attachments_content field where the content of a document is stored.
$query = new \Elastica\Query([ 'query' => [ 'term' => ['_all' => $search_term], ], ]);
Then I used
$query = new \Elastica\Query([ ‘query’ => [ ‘bool’ => [ ‘should’ => [ [‘match_phrase’ => [ ‘title’ => $search_term ] ], [‘match_phrase’ => [ ‘body:value’ => $search_term ] ], [‘match_phrase’ => [ ‘attachments_content’ => $search_term ] ], ], ], ] ]);
It was still able to search for the term in title pages, content pages, title documents but now it returns every document even if it is not related to the term.