Paul
Paul

Reputation: 868

Filtering on a multiple word string in a field (elasticsearch 1.1)

My json query:

{
   "size": 3,
   "query": {
        "filtered": {
            "query": { "match_all": {} },
            "filter": { "term": { "publication_type": "horse mouth" }}
        }
    }
}

Does anyone know how to search for the two words "horse mouth" in the field publication_type?

Atm I can only get results when i search for "horse" or "mouth"..

Working with elasticsearch 1.1

Upvotes: 0

Views: 689

Answers (1)

keety
keety

Reputation: 17461

you could use the terms filter for this. You can use execution mode to "and" if you want all the terms to be present in the document. The default is equivalent to an "or"

Example:

{
   "size": 3,
   "query": {
        "filtered": {
            "query": { "match_all": {} },
            "filter": { "terms": { "publication_type": ["horse", "mouth"]}}
        }
    }
}

Upvotes: 2

Related Questions