From 607c35f39151166694493684b8d55b06450ba967 Mon Sep 17 00:00:00 2001 From: Remi Dettai Date: Tue, 10 Dec 2024 14:11:47 +0100 Subject: [PATCH] Add tests to show failing exist queries --- .../quickwit-doc-mapper/src/query_builder.rs | 31 ++++++++++ .../es_compatibility/0011-exists-query.yaml | 10 ++++ .../qw_search_api/0004_exists_search.yaml | 60 +++++++++++++++++++ .../qw_search_api/_setup.quickwit.yaml | 37 +++++++++++- .../qw_search_api/_teardown.quickwit.yaml | 3 + 5 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 quickwit/rest-api-tests/scenarii/qw_search_api/0004_exists_search.yaml diff --git a/quickwit/quickwit-doc-mapper/src/query_builder.rs b/quickwit/quickwit-doc-mapper/src/query_builder.rs index dbc663794e5..791a128186d 100644 --- a/quickwit/quickwit-doc-mapper/src/query_builder.rs +++ b/quickwit/quickwit-doc-mapper/src/query_builder.rs @@ -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, }; @@ -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); @@ -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); } @@ -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() { { diff --git a/quickwit/rest-api-tests/scenarii/es_compatibility/0011-exists-query.yaml b/quickwit/rest-api-tests/scenarii/es_compatibility/0011-exists-query.yaml index 8de231391e5..154ce7a432f 100644 --- a/quickwit/rest-api-tests/scenarii/es_compatibility/0011-exists-query.yaml +++ b/quickwit/rest-api-tests/scenarii/es_compatibility/0011-exists-query.yaml @@ -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: diff --git a/quickwit/rest-api-tests/scenarii/qw_search_api/0004_exists_search.yaml b/quickwit/rest-api-tests/scenarii/qw_search_api/0004_exists_search.yaml new file mode 100644 index 00000000000..35739d79a34 --- /dev/null +++ b/quickwit/rest-api-tests/scenarii/qw_search_api/0004_exists_search.yaml @@ -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 diff --git a/quickwit/rest-api-tests/scenarii/qw_search_api/_setup.quickwit.yaml b/quickwit/rest-api-tests/scenarii/qw_search_api/_setup.quickwit.yaml index 84270d975b4..9c5542af5fe 100644 --- a/quickwit/rest-api-tests/scenarii/qw_search_api/_setup.quickwit.yaml +++ b/quickwit/rest-api-tests/scenarii/qw_search_api/_setup.quickwit.yaml @@ -68,7 +68,8 @@ params: ndjson: - {"seq": 1, "tag": 1} - {"seq": 2, "tag": 2} ----method: POST +--- +method: POST endpoint: tagged/ingest params: commit: force @@ -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}} diff --git a/quickwit/rest-api-tests/scenarii/qw_search_api/_teardown.quickwit.yaml b/quickwit/rest-api-tests/scenarii/qw_search_api/_teardown.quickwit.yaml index a2896f541b1..614b1ffb058 100644 --- a/quickwit/rest-api-tests/scenarii/qw_search_api/_teardown.quickwit.yaml +++ b/quickwit/rest-api-tests/scenarii/qw_search_api/_teardown.quickwit.yaml @@ -4,3 +4,6 @@ endpoint: indexes/simple --- method: DELETE endpoint: indexes/tagged +--- +method: DELETE +endpoint: indexes/json