Note that there are some explanatory texts on larger screens.

plurals
  1. POElasticsearch: is there a way to declare for all (possibly dynamic) subfields of an object field as string?
    primarykey
    data
    text
    <p>I have a doc_type with a mapping similar to this very simplified one:</p> <pre><code>{ "test":{ "properties":{ "name":{ "type":"string" }, "long_searchable_text":{ "type":"string" }, "clearances":{ "type":"object" } } } } </code></pre> <p>The field <code>clearances</code> should be an object, with a series of alphanumeric identifiers for filtering purposes. A typical document will have this format:</p> <pre><code>{ "name": "Lord Macbeth", "long_searchable_text": "Life's but a walking shadow, a poor player, that..." "clearances": { "glamis": "aa2862jsgd", "cawdor": "3463463551" } } </code></pre> <p>The problem is that sometimes during indexing, the first indexed content of a new field inside the object field <code>clearances</code> will be completely numerical, as in the case above. This causes Elasticsearch to infer the type of this field as <code>long</code>. But this is an accident. The field might be alphanumeric in another document. When a latter document containing an alphanumeric value in this field arrive, I get a parsing exception:</p> <pre><code>{"error":"MapperParsingException[failed to parse [clearances.cawdor]]; nested: NumberFormatException[For input string: \"af654hgss1\"]; ","status":400}% </code></pre> <p>I tried to solve this with a dynamic template defined like this:</p> <pre><code>{ "test":{ "properties":{ "name":{ "type":"string" }, "long_searchable_text":{ "type":"string" }, "clearances":{ "type":"object" } } }, "dynamic_templates":[ { "source_template":{ "match":"clearances.*", "mapping":{ "type":"string", "index":"not_analyzed" } } } ] } </code></pre> <p>But it keeps happening that if the first indexed document have a <code>clearance.some_subfield</code> value that can be parsed as an integer, it would be inferred as an integer and all subsequent documents that have alphanumeric values on that subfield will fail to be indexed.</p> <p>I could list all current subfields in the the mapping, but they are many and I expect their number to grow in the future (triggering an update of the mapping and a need for a full reindexation...). </p> <p>Is there a way to make this work without resorting to this full reindexation everytime a new subfield is added?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload