Skip to content

Commit

Permalink
fix index pattern matching in fieldcaps
Browse files Browse the repository at this point in the history
align the index pattern matching behaviour to elasticsearch.
That means empty results if the index pattern matches nothing but
contains a wildcard.
Error if the index pattern matches nothing but is exact.
  • Loading branch information
PSeitz committed Dec 19, 2023
1 parent 66d27b5 commit fcbe8b5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
16 changes: 8 additions & 8 deletions quickwit/quickwit-search/src/list_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use quickwit_proto::types::IndexUid;
use quickwit_storage::Storage;

use crate::leaf::open_split_bundle;
use crate::root::check_all_index_metadata_found;
use crate::service::SearcherContext;
use crate::{list_relevant_splits, ClusterClient, SearchError, SearchJob};

Expand Down Expand Up @@ -292,23 +293,22 @@ pub async fn root_list_fields(
ListIndexesMetadataRequest::all()
} else {
ListIndexesMetadataRequest {
// TODO: Check index id pattern
index_id_patterns: list_fields_req.index_ids.clone(),
}
};

// Get the index ids from the request
let indexes_metadatas = metastore
let indexes_metadata = metastore
.clone()
.list_indexes_metadata(list_indexes_metadata_request)
.await?
.deserialize_indexes_metadata()?;
if indexes_metadatas.is_empty() {
return Err(SearchError::IndexesNotFound {
index_ids: list_fields_req.index_ids.clone(),
});
check_all_index_metadata_found(&indexes_metadata[..], &list_fields_req.index_ids[..])?;
// The request contains a wildcard, but couldn't find any index.
if indexes_metadata.is_empty() {
return Ok(ListFieldsResponse { fields: vec![] });
}
let index_uid_to_index_meta: HashMap<IndexUid, IndexMetasForLeafSearch> = indexes_metadatas
let index_uid_to_index_meta: HashMap<IndexUid, IndexMetasForLeafSearch> = indexes_metadata
.iter()
.map(|index_metadata| {
let index_metadata_for_leaf_search = IndexMetasForLeafSearch {
Expand All @@ -322,7 +322,7 @@ pub async fn root_list_fields(
)
})
.collect();
let index_uids: Vec<IndexUid> = indexes_metadatas
let index_uids: Vec<IndexUid> = indexes_metadata
.into_iter()
.map(|index_metadata| index_metadata.index_uid)
.collect();
Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-search/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ fn finalize_aggregation_if_any(
/// We put this check here and not in the metastore to make sure the logic is independent
/// of the metastore implementation, and some different use cases could require different
/// behaviors. This specification was principally motivated by #4042.
fn check_all_index_metadata_found(
pub fn check_all_index_metadata_found(
index_metadatas: &[IndexMetadata],
index_id_patterns: &[String],
) -> crate::Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,63 @@ expected:
metadata_field: false
searchable: true
aggregatable: true
---
# Wildcard on index name
method: [GET]
engines:
- quickwit
- elasticsearch
endpoint: fieldca*/_field_caps?fields=date
expected:
indices:
- fieldcaps
fields:
date:
date_nanos:
type: date_nanos
metadata_field: false
searchable: true
aggregatable: true
---
# Wildcard on index name + Wildcard without match
method: [GET]
engines:
- quickwit
- elasticsearch
endpoint: fieldca*,blub*/_field_caps?fields=date
expected:
indices:
- fieldcaps
fields:
date:
date_nanos:
type: date_nanos
metadata_field: false
searchable: true
aggregatable: true

---
# Exact match index + Non matching excact index
method: [GET]
engines:
- quickwit
- elasticsearch
endpoint: fieldcaps,blub/_field_caps?fields=date
status_code: 404
---
# Compare ip field with elastic search
method: [GET]
engines:
- quickwit
- elasticsearch
endpoint: doesnotexist/_field_caps?fields=date
status_code: 404
---
# Compare ip field with elastic search
method: [GET]
engines:
- quickwit
- elasticsearch
endpoint: doesno*texist/_field_caps?fields=date
status_code: 200

0 comments on commit fcbe8b5

Please sign in to comment.