0
votes

I'm trying to use a query in Elastic Search, where all English("taal":"engels") books are ignored. I thought I should use a bool query, and a must_not, with the condition the term "taal":"Engels" inside the query.

GET books/_search
{
  "query": { 
    "bool": { 
      "must_not" : {
        "term" : { "taal" : "Engels" }
      }
    }
  }
}

However, when running this query in Kibana it still shows results with language = english.

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 501,
    "max_score": 1,
    "hits": [
      {
        "_index": "producten4",
        "_type": "boek",
        "_id": "9780582401815",
        "_score": 1,
        "_source": {
          "isbn": "9780582401815",
          "hoofdtitel": "Forrest Gump",
          "taal": "Engels",
        }
      },
      ETCETERA....
    ]
  }
}

Mapping of the field taal:

"taal": {
  "type": "text",
  "fields": {
    "keyword": {
      "type": "keyword",
      "ignore_above": 256
    },
    "raw": {
      "type": "keyword"
    },
    "taal": {
      "type": "text"
    }
  }
}
2

2 Answers

0
votes

try using "match" instead of "term"?

0
votes

I've fixed it by adding .raw to the fieldname:

bool: {
    must_not: [
      {
        term: {
          'taal.raw': 'Engels',
        }
      },
      {
        term: {
          'taal.raw': 'Nederlands',
        }
      }]
    }