Skip to content

Commit

Permalink
document valid conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
trinity-1686a committed Sep 27, 2024
1 parent 6ba418a commit 02f2edb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
37 changes: 36 additions & 1 deletion docs/reference/updating-mapper.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See example 1 and 2 below for clarification.
Change in tokenizer affect only newer splits, older splits keep using the tokenizers they were created with.

Document retrieved are mapped from Quickwit internal format to JSON based on the latest doc mapping. This means if fields are deleted,
they will stop appearing (see also Reversibility below). If the type of some field changed, it will be converted on a best effort basis:
they will stop appearing (see also Reversibility below) unless mapper mode is Dynamic. If the type of some field changed, it will be converted on a best effort basis:
integers will get turned into text, text will get turned into string when it is possible, otherwise, the field is omited.
See example 3 for clarification.

Expand All @@ -31,6 +31,41 @@ receiving a new doc mapping. If you realize you updated the mapping in a way tha
mapping. Documents indexed while the mapping was wrong will be impacted, but any document that was commited before the change will be
back to its original state.


## Type update reference

Conversion from a type to itself is omited. Conversion which never succeed and always omit the field are omited too.

<!-- this is extracted from `quickwit_doc_mapper::::default_doc_mapper::value_to_json()` -->
| type before | type after | behavior |
|-------------|------------|
| u64/i64/f64 | text | convert to decimal string |
| date | text | convert to rfc3339 textual representation |
| ip | text | convert to IPv6 representation. For IPv4, convert to IPv4-mapped IPv6 address (`::ffff:1.2.3.4`) |
| bool | text | convert to "true" or false" |
| u64/i64/f64 | bool | convert 0/0.0 to false and 1/1.0 to true, otherise omit |
| text | bool | convert if "true" or "false" (lowercase), otherwise omit |
| text | ip | convert if valid IPv4 or IPv6, otherwise omit |
| text | f64 | convert if valid floating point number, otherwise omit |
| u64/i64 | f64 | convert, possibly with loss of precision |
| bool | f64 | convert to 0.0 for false, and 1.0 for true |
| text | u64 | convert is valid integer in range 0..2\*\*64, otherwise omit |
| i64 | u64 | convert if in range 0..2\*\*63, otherwise omit |
| f64 | u64 | convert if in range 0..2\*\*64, possibly with loss of precision, otherwise omit |
| text | i64 | convert is valid integer in range -2\*\*63..2\*\*63, otherwise omit |
| u64 | i64 | convert if in range 0..2\*\*63, otherwise omit |
| f64 | i64 | convert if in range -2\*\*63..2\*\*63, possibly with loss of precision, otherwise omit |
| bool | i64 | convert to 0 for false, and 1 for true |
| text | datetime | parse according to current input\_format, otherwise omit |
| u64 | datetime | parse according to current input\_format, otherwise omit |
| i64 | datetime | parse according to current input\_format, otherwise omit |
| f64 | datetime | parse according to current input\_format, otherwise omit |
| array\<T\> | array\<U\> | convert individual elements, skipping over those which can't be converted |
| T | array\<U\> | convert element, emiting array of a single element, or empty array if it can't be converted |
| array\<T\> | U | convert individual elements, keeping the first which can be converted |
| json | object | try convert individual elements if they exists inside object, omit individual elements which can't be |
| object | json | convert individual elements. Previous lists of one element are converted to a single element not in an array.

## Examples

In all exemples, fields which are not relevant are removed for conciseness, you will not be able to use these index config as is.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,11 @@ fn value_to_bool(value: TantivyValue) -> Result<JsonValue, TantivyValue> {
1 => Some(true),
_ => None,
},
TantivyValue::F64(number) => match number {
0.0 => Some(false),
1.0 => Some(true),
_ => None,
},
TantivyValue::Bool(b) => Some(*b),
_ => None,
}
Expand Down

0 comments on commit 02f2edb

Please sign in to comment.