-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To view the current field limits.
- Loading branch information
Showing
2 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
// SPDX-FileCopyrightText: (C) 2022 Jason Ish <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
use crate::cli::elastic::info; | ||
use anyhow::Result; | ||
use clap::{Command, CommandFactory, FromArgMatches, Parser, Subcommand}; | ||
use tracing::info; | ||
|
||
use super::set_field_limit; | ||
|
||
|
@@ -42,8 +43,12 @@ pub(crate) struct ElasticOptions { | |
pub(crate) enum Commands { | ||
/// Display infomratiot about the Elasticsearch server | ||
Info(ElasticOptions), | ||
|
||
/// Set the field limit | ||
SetFieldLimit(set_field_limit::Args), | ||
|
||
/// Get the field limit. | ||
GetFieldLimit, | ||
} | ||
|
||
pub fn main_options() -> Command { | ||
|
@@ -53,8 +58,52 @@ pub fn main_options() -> Command { | |
pub async fn main(args: &clap::ArgMatches) -> anyhow::Result<()> { | ||
let args = Args::from_arg_matches(args)?; | ||
match args.commands { | ||
Commands::Info(args) => info::main(args).await?, | ||
Commands::Info(args) => crate::cli::elastic::info::main(args).await?, | ||
Commands::SetFieldLimit(args) => set_field_limit::main(args).await?, | ||
Commands::GetFieldLimit => get_field_limit(&args).await?, | ||
} | ||
Ok(()) | ||
} | ||
|
||
async fn get_field_limit(args: &Args) -> Result<()> { | ||
let mut client = crate::elastic::client::ClientBuilder::new(&args.options.elasticsearch) | ||
.disable_certificate_validation(true); | ||
if let Some(username) = &args.options.username { | ||
client = client.with_username(username); | ||
} | ||
if let Some(password) = &args.options.password { | ||
client = client.with_password(password); | ||
} | ||
let client = client.build(); | ||
|
||
for index in client.get_indices_pattern("*").await? { | ||
// Only look at indices that match the name-YYYY.MM.DD | ||
// pattern. | ||
if regex::Regex::new(r"^\w+-\d{4}\.\d{2}\.\d{2}$")? | ||
.find(&index.index) | ||
.is_none() | ||
{ | ||
continue; | ||
} | ||
|
||
let settings = client.get_index_settings(&index.index).await?; | ||
if let Some(map) = settings.as_object() { | ||
for (index, settings) in map { | ||
let limit = &settings["settings"]["index"]["mapping"]["total_fields"]["limit"]; | ||
match limit { | ||
serde_json::Value::Number(limit) => { | ||
info!("{}: {}", index, limit); | ||
} | ||
serde_json::Value::String(limit) => { | ||
info!("{}: {}", index, limit); | ||
} | ||
_ => { | ||
info!("{}: default (likely 1000)", index); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters