Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal Server Error when Adding STAC Collection to Geoportal Server #594

Open
Anna-leungtn opened this issue Jan 21, 2025 · 4 comments
Open
Assignees

Comments

@Anna-leungtn
Copy link

I am experiencing an issue while attempting to add the sample JSON STAC collection to the Geoportal Server catalog. Upon submission, I encounter the following error:

Image

It appears that the error is related to a missing property in the JSON payload. I would appreciate any guidance on resolving this issue or any updates regarding a potential fix.

@eltonhcchan
Copy link

When trying to post a new STAC collection in geoportal via STAC API, geoportal would check the collection id if it exists in the elasticsearch.

Upon an id is retrieved from given collection.json, it will use getCollectionWithId(String id) function in Stachelper.java, to check if same id can be found in existing index, i.e. collections.

DocumentContext elasticResContext = JsonPath.parse(response);
 **// When reading "$hits", it will jump to error 404 as the index: collections is yet to be created**
net.minidev.json.JSONArray items = elasticResContext.read("$.hits.hits");
JSONObject item = null;

It seems geoportal should have created or checked the index "collections" before getting no. of returned hits but didn't do it. I've tested it in release 2.7.2. Not sure, if it works in latest release 2.7.2.1 as I still cannot compile it successfully. Please advise.

@mhogeweg
Copy link
Member

Geoportal Server does check if the index exists and if not creates it. this happens when Tomcat is restarted. Does your collection index not exist?

@reeve718
Copy link

StacHelper.java

public static JSONObject getCollectionWithId(String id) throws Exception {
		String response = "";		
		String query = "";
		
		ElasticContext ec = GeoportalContext.getInstance().getElasticContext();
		ElasticClient client = ElasticClient.newClient();
		String url = client.getTypeUrlForSearch(ec.getCollectionIndexName());
		Map<String, String> queryMap = new HashMap<String, String>();

		queryMap.put("ids", id);
		url = url + "/_search";
		
		query = prepareSearchQuery(queryMap, null);
                if (query.length() > 0)
			response = client.sendPost(url, query, "application/json");
		else
			response = client.sendGet(url);
		
		DocumentContext elasticResContext = JsonPath.parse(response);
		net.minidev.json.JSONArray items = elasticResContext.read("$.hits.hits");

From the code segment above, the getCollectionWithId function is trying to query elasticsearch with url string which get by client.getTypeUrlForSearch(ec.getCollectionIndexName());
As the result, it is querying the end point: http://localhost:9200/collections/_search
However, the default index name in geoportal catalog used is "metadata".
Therefore, the elasticsearch response as below:

 {
    "error": {
        "root_cause": [
            {
                "type": "index_not_found_exception",
                "reason": "no such index [collection]",
                "resource.type": "index_or_alias",
                "resource.id": "collection",
                "index_uuid": "_na_",
                "index": "collection"
            }
        ],
        "type": "index_not_found_exception",
        "reason": "no such index [collection]",
        "resource.type": "index_or_alias",
        "resource.id": "collection",
        "index_uuid": "_na_",
        "index": "collection"
    },
    "status": 404
}

Exception thrown on net.minidev.json.JSONArray items = elasticResContext.read("$.hits.hits");

By fixing the index name such that url = http://localhost:9200/metadata_v1/_search, the response should be like as below:

{
    "took": 15,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 0,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    }
}

Attached variables in debug mode:

Image

@as0050629
Copy link
Collaborator

as0050629 commented Feb 14, 2025

@Anna-leungtn Collection index is auto created when tomcat is started. Please share your app-context.xml or validate that below property (in bold) exists in your config

<beans:bean id="elasticContext" class="com.esri.geoportal.lib.elastic.ElasticContextHttp">
<beans:property name="clusterName" value="elasticsearch" />
<beans:property name="indexName" value="${gpt_indexName:metadata}" />
<beans:property name="collectionIndexName" value="${gpt_collectionIndexName:collections}" />
<beans:property name="indexNameIsAlias" value="true" />
<beans:property name="autoCreateIndex" value="true" />
<beans:property name="autoCreateCollectionIndex" value="true" />

If you do not see this property in your config, please take latest code from master branch or https://github.com/Esri/geoportal-server-catalog/releases/tag/v2.7.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants