Skip to content

Commit

Permalink
Add tests to show failing exist queries
Browse files Browse the repository at this point in the history
  • Loading branch information
rdettai committed Dec 10, 2024
1 parent 7ec03f9 commit 607c35f
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 1 deletion.
31 changes: 31 additions & 0 deletions quickwit/quickwit-doc-mapper/src/query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ fn extract_prefix_term_ranges(
mod test {
use std::ops::Bound;

use quickwit_common::shared_consts::FIELD_PRESENCE_FIELD_NAME;
use quickwit_query::query_ast::{
query_ast_from_user_text, FullTextMode, FullTextParams, PhrasePrefixQuery, QueryAstVisitor,
};
Expand All @@ -295,6 +296,7 @@ mod test {

fn make_schema(dynamic_mode: bool) -> Schema {
let mut schema_builder = Schema::builder();
schema_builder.add_i64_field(FIELD_PRESENCE_FIELD_NAME, INDEXED);
schema_builder.add_text_field("title", TEXT);
schema_builder.add_text_field("desc", TEXT | STORED);
schema_builder.add_text_field("server.name", TEXT | STORED);
Expand All @@ -311,6 +313,8 @@ mod test {
schema_builder.add_u64_field("u64_fast", FAST | STORED);
schema_builder.add_i64_field("i64_fast", FAST | STORED);
schema_builder.add_f64_field("f64_fast", FAST | STORED);
schema_builder.add_json_field("json_fast", FAST);
schema_builder.add_json_field("json_text", TEXT);
if dynamic_mode {
schema_builder.add_json_field(DYNAMIC_FIELD_NAME, TEXT);
}
Expand Down Expand Up @@ -503,6 +507,33 @@ mod test {
);
}

#[test]
fn test_existence_query() {
check_build_query_static_mode(
"title:*",
Vec::new(),
TestExpectation::Ok("TermQuery(Term(field=0, type=U64"),
);

check_build_query_static_mode(
"ip:*",
Vec::new(),
TestExpectation::Ok("ExistsQuery { field_name: \"ip\" }"),
);

check_build_query_static_mode(
"json_text:*",
Vec::new(),
TestExpectation::Ok("TermQuery(Term(field=0, type=U64"),
);

check_build_query_static_mode(
"json_fast:*",
Vec::new(),
TestExpectation::Ok("ExistsQuery { field_name: \"json_fast\" }"),
);
}

#[test]
fn test_datetime_range_query() {
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ expected:
total:
value: 60
---
json:
query:
exists:
field: payload
expected:
hits:
total:
# one of the docs contains `"payload":{}`
value: 99
---
# Fortunately, ES does not accept this quirky syntax in the
# case of exists query.
json:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

endpoint: json/search
params:
query: "json_fast:*"
expected:
num_hits: 1
---
endpoint: json/search
params:
query: "json_text:*"
expected:
num_hits: 2
---
endpoint: json/search
params:
query: "json_text.field_a:*"
expected:
num_hits: 2
---
endpoint: json/search
params:
query: "json_text.field_b:*"
expected:
num_hits: 1
---
endpoint: json/search
params:
query: "json_fast.fast_field_a:*"
expected:
num_hits: 1
---
endpoint: json/search
params:
query: "json_fast.doesnotexist:*"
expected:
num_hits: 0
---
endpoint: json/search
params:
query: "object_multi:*"
expected:
num_hits: 3
---
endpoint: json/search
params:
query: "object_multi.object_text_field:*"
expected:
num_hits: 1
---
endpoint: json/search
params:
query: "object_multi.object_fast_field:*"
expected:
num_hits: 2
---
endpoint: json/search
params:
query: "object_multi.doesnotexist:*"
expected:
num_hits: 0
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ params:
ndjson:
- {"seq": 1, "tag": 1}
- {"seq": 2, "tag": 2}
---method: POST
---
method: POST
endpoint: tagged/ingest
params:
commit: force
Expand All @@ -82,3 +83,37 @@ params:
commit: force
ndjson:
- {"seq": 4, "tag": 1}
---
method: POST
endpoint: indexes/
json:
version: "0.7"
index_id: json
doc_mapping:
field_mappings:
- name: json_text
type: json
- name: json_fast
type: json
fast: true
- name: object_multi
type: object
field_mappings:
- name: object_text_field
type: text
- name: object_fast_field
type: u64
fast: true

---
method: POST
endpoint: tagged/ingest
params:
commit: force
ndjson:
- {"json_text": {"field_a": "hello", "field_b": "world"}}
- {"json_text": {"field_a": "hi"}}
- {"json_fast": {"field_c": 1}}
- {"object_multi": {"object_text_field": "multi hello"}}
- {"object_multi": {"object_fast_field": 1}}
- {"object_multi": {"object_fast_field": 2}}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ endpoint: indexes/simple
---
method: DELETE
endpoint: indexes/tagged
---
method: DELETE
endpoint: indexes/json

0 comments on commit 607c35f

Please sign in to comment.