mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-10 20:35:17 +02:00
feat: enhance Elasticsearch connector to handle missing index configuration
This commit is contained in:
parent
c3d249682f
commit
72e8d98f40
3 changed files with 12 additions and 14 deletions
|
|
@ -53,7 +53,7 @@ def upgrade() -> None:
|
|||
|
||||
def downgrade() -> None:
|
||||
"""Remove 'ELASTICSEARCH_CONNECTOR' from enum types.
|
||||
|
||||
|
||||
Note: PostgreSQL does not support removing enum values that may be in use.
|
||||
Manual intervention would be required if rollback is necessary:
|
||||
1. Delete all rows using ELASTICSEARCH_CONNECTOR
|
||||
|
|
|
|||
|
|
@ -111,12 +111,13 @@ async def index_elasticsearch_documents(
|
|||
logger.error(error_msg)
|
||||
return 0, error_msg
|
||||
|
||||
if "ELASTICSEARCH_INDEX" not in config:
|
||||
error_msg = (
|
||||
"Missing required field in connector config: ELASTICSEARCH_INDEX"
|
||||
# Allow missing/empty index: default to searching all indices ("*" or "_all")
|
||||
index_name = config.get("ELASTICSEARCH_INDEX")
|
||||
if not index_name:
|
||||
index_name = "*"
|
||||
logger.info(
|
||||
"ELASTICSEARCH_INDEX missing or empty in connector config; defaulting to '*' (search all indices)"
|
||||
)
|
||||
logger.error(error_msg)
|
||||
return 0, error_msg
|
||||
|
||||
# Check authentication - must have either API key or username+password
|
||||
has_api_key = (
|
||||
|
|
@ -151,9 +152,6 @@ async def index_elasticsearch_documents(
|
|||
# Build query based on configuration
|
||||
query = _build_elasticsearch_query(config)
|
||||
|
||||
# Get the index name(s) - can be a string or list
|
||||
index_name = config["ELASTICSEARCH_INDEX"]
|
||||
|
||||
# Get max documents to index
|
||||
max_documents = config.get("ELASTICSEARCH_MAX_DOCUMENTS", 1000)
|
||||
|
||||
|
|
@ -341,7 +339,7 @@ def _build_document_content(source: dict[str, Any], config: dict[str, Any]) -> s
|
|||
field_value = source[field]
|
||||
if isinstance(field_value, str | int | float):
|
||||
content_parts.append(f"{field}: {field_value}")
|
||||
if isinstance(field_value, str | int | float):
|
||||
elif isinstance(field_value, list | dict):
|
||||
content_parts.append(f"{field}: {json.dumps(field_value)}")
|
||||
else:
|
||||
# Use all fields if no specific content fields specified
|
||||
|
|
|
|||
|
|
@ -150,10 +150,10 @@ export default function ElasticsearchConnectorPage() {
|
|||
config.ELASTICSEARCH_API_KEY = values.ELASTICSEARCH_API_KEY;
|
||||
}
|
||||
|
||||
if (values.indices?.trim()) {
|
||||
const indicesArr = stringToArray(values.indices);
|
||||
config.ELASTICSEARCH_INDEX = indicesArr.length === 1 ? indicesArr[0] : indicesArr;
|
||||
}
|
||||
const indicesInput = values.indices?.trim() ?? "";
|
||||
const indicesArr = stringToArray(indicesInput);
|
||||
config.ELASTICSEARCH_INDEX =
|
||||
indicesArr.length === 0 ? "*" : indicesArr.length === 1 ? indicesArr[0] : indicesArr;
|
||||
|
||||
if (values.query && values.query !== "*") {
|
||||
config.ELASTICSEARCH_QUERY = values.query;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue