Search code examples
elasticsearchelasticsearch-dsl

elasticsearch wildcard doesn't return any results


I have a text of a judgment in which "avv. mario rossi" appears. The text of the judgment is as follows:

"n. 936/2020 r.g. concerning the cessation of civil effects of the marriage promoted by name surname, born in novara (no) on 12.07.1967, residing in borgomanero, via coco x n. x, electively domiciled in borgomanero, via s. giovanni n. 7, at the law firm of avv. mario rossi, by whom she is represented and defended, pursuant to a power of attorney in the records; - petitioner - against x x x, born on 24.6.1957 in mezzomerico, residing in vaprio d'agogna, via x n. 29/b - defendant in default - and with the intervention of the public prosecutor in the final arguments of the petitioner:"

The text is written in a field of a document that has the following mapping:

"text": {
 "type": "text",
 "fields": {
   "keyword": {
     "type": "keyword",
     "ignore_above": 256
   }
 }
}

The query that I'm trying to execute, which doesn't return any results, is this:

{
  "query": {
    "bool": {
      "must": [
        {
          "wildcard": {
            "text.keyword": "*a?v. mario rossi*"
          }
        }
      ],
      "should": []
    }
  }
}

Why is the document not returning? Is it because of the ignore_above setting, which might be too low? I don't think it because "a?v. mario rossi" is 15 caracthers length.

UPDATE

{
  "mappings": {
    "properties": {
      "text": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        },
        "store": true    <-------- Add this line to enable storing the text.keyword field
      }
    }
  }
}

"Once the "text.keyword" field is stored, you can access it in the response and use wildcard queries on it" Is true? How do I reindex my_index elasticsearch with this new mapping? Do I change mapping of my_index and then copy into new_index?

Keep in mind that explicitly storing fields can increase storage requirements, so use it judiciously based on your specific use case and requirements.


Solution

  • It is because the text you have indexed is greater than 256 characters. So it doesn't actually create the keyword subfield for you. By indexing, again with your exact mapping and using your exact query, a much shorter text your query works.