1

I want to find a document with a name that contains 'Bob' and has a location that is in either 'paducah' or 'smyrna'.

Here's what I have now:

query: {
  bool: {
    must: [
      { match: { name: 'bob' } }, 
      { match: { location: ['paducah', 'smyrna'] } }
    ],
  },
},

I know the problem is in the location array, because if i change it to a single element with no array the query works just fine.

This is the closest answer i could find.

It didn't work, i receive the following error:

[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]

SweetCoco
  • 91
  • 1
  • 7

2 Answers2

3

You could try this query:

{
    "query": {
      "bool": {
        "must": [
          { "match": { "name": "bob" } }
        ],
        "should": [
            { "match": { "location": "paducah" }},
            { "match": { "location": "smyrna"   }}
          ],
          "minimum_should_match": 1
      }
    }
}
Joanna Mamczynska
  • 2,148
  • 16
  • 14
0

What about the following:

{
  "query": {
    "bool": {
      "must": [
        { "term": { "name": "bob" }, 
        "bool": {
          "should": [
            {"term": {"location": "paducah"}},
            {"term": {"location": "smyrna"}}
          ]
        }
        }
      ]
    }
  }
}
alpert
  • 4,500
  • 1
  • 17
  • 27