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

Elasticssearch 8 upgrade #7599

Merged
merged 28 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ace0c8b
Update to Elasticsearch 8. Use of Elasticsearch Java API Client inste…
josegar74 Oct 15, 2023
75c715c
Update to Elasticsearch 8 / WFS indexing draft. (#88)
fxprunayre Oct 31, 2023
79e257e
Update to Elasticsearch 8 / remove TODOs
josegar74 Nov 1, 2023
2b45ddd
Update Elasticsearch client to version 8.11.3
josegar74 Jan 8, 2024
72ed58e
Elasticsearch / Update maven plugin.
fxprunayre Jan 8, 2024
4004b10
Associated record / Store all relations in index / Remove experimenta…
josegar74 Jan 8, 2024
c51d81e
Elasticsearch / Update maven plugin configuration. Avoid error like E…
fxprunayre Jan 8, 2024
fe2ade7
Elasticsearch / Update MetadataUtils.getAssociated to retrieve script…
josegar74 Jan 8, 2024
b2425f5
Elasticsearch / Update MetadataUtils.getAssociated remove TODO comment
josegar74 Jan 8, 2024
765e338
Elasticsearch / Fix and refactor index readonly health check
josegar74 Jan 8, 2024
4017061
Elasticsearch / Log query error details
josegar74 Jan 8, 2024
c76772d
Elasticsearch / Sonarlint improvements
josegar74 Jan 8, 2024
b347d6b
Elasticsearch / WrapperQuery use base64 encoded JSON string query.
fxprunayre Jan 8, 2024
a77e2cc
Elasticsearch / Remove unused commented code from EsSearchManager
josegar74 Jan 8, 2024
8d92752
Elasticsearch / More strict Xlink query based on UUID and fix check o…
fxprunayre Jan 9, 2024
6e5b156
Elasticsearch / Health check / Fix number of hits info.
fxprunayre Jan 9, 2024
e0f1980
Elasticsearch / Cleaning / No need to retrieve hits to only get matches.
fxprunayre Jan 9, 2024
e1bf8f9
Elasticsearch / Deprecated field [include] used, expected [includes] …
fxprunayre Jan 9, 2024
e4c61b2
Elasticsearch / Remove 'Clear XLink cache' from Administration > Tool…
josegar74 Jan 9, 2024
312b21e
Kibana / Update install instruction
fxprunayre Jan 9, 2024
ad130e7
Elasticsearch / Remove unused imports
josegar74 Jan 9, 2024
5a3e8ec
Kibana / Update default dashboards.
fxprunayre Jan 9, 2024
9bbb602
Elasticsearch / Documentation / Update Elasticsearch version
josegar74 Jan 9, 2024
c65b7ab
Elasticsearch / Fix logger module name typo
josegar74 Jan 9, 2024
02b99be
Merge remote-tracking branch 'origin/main' into elasticssearch8-upgrade
josegar74 Jan 11, 2024
53281db
Merge branch 'main' into elasticssearch8-upgrade
josegar74 Jan 22, 2024
f375b6f
Merge branch 'main' into elasticssearch8-upgrade
josegar74 Jan 23, 2024
4c3ea7e
Merge branch 'main' into elasticssearch8-upgrade
josegar74 Feb 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,10 @@
<artifactId>spring-test</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
</dependency>

<dependency>
Expand Down Expand Up @@ -695,6 +696,7 @@
<clusterName>test</clusterName>
<transportPort>9300</transportPort>
<httpPort>9200</httpPort>
<environmentVariables><ES_JAVA_OPTS>-Xmx2g</ES_JAVA_OPTS></environmentVariables>
</configuration>
<executions>
<execution>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/fao/geonet/constants/Geonet.java
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ public static final class Namespaces {

public static class IndexFieldNames {
public static final String HASXLINKS = "_hasxlinks";
public static final String XLINK = "_xlink";
public static final String XLINK = "xlink";
public static final String ROOT = "_root";
public static final String SCHEMA = "documentStandard";
public static final String DATABASE_CREATE_DATE = "createDate";
Expand Down
7 changes: 1 addition & 6 deletions core/src/main/java/org/fao/geonet/kernel/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//=== DataManager
//===
//=============================================================================
//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
//=== Copyright (C) 2001-2023 Food and Agriculture Organization of the
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
//=== and United Nations Environment Programme (UNEP)
//===
Expand Down Expand Up @@ -143,11 +143,6 @@ public void init(ServiceContext context, Boolean force) throws Exception {
}
}

@Deprecated
public synchronized void rebuildIndexXLinkedMetadata(final ServiceContext context) throws Exception {
metadataIndexer.rebuildIndexXLinkedMetadata(context);
}

@Deprecated
public synchronized void rebuildIndexForSelection(final ServiceContext context, String bucket, boolean clearXlink) throws Exception {
metadataIndexer.rebuildIndexForSelection(context, bucket, clearXlink);
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/java/org/fao/geonet/kernel/SelectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@

package org.fao.geonet.kernel;

import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.search.Hit;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import jeeves.server.UserSession;
import jeeves.server.context.ServiceContext;

import org.apache.commons.lang.StringUtils;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.SearchHit;
import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.constants.Edit;
import org.fao.geonet.constants.Geonet;
Expand Down Expand Up @@ -248,8 +249,9 @@ public void selectAll(String type, ServiceContext context, UserSession session)
EsSearchManager searchManager = context.getBean(EsSearchManager.class);
searchResponse = searchManager.query(request.get("query"), FIELDLIST_UUID, 0, maxhits);
List<String> uuidList = new ArrayList();
for (SearchHit h : Arrays.asList(searchResponse.getHits().getHits())) {
uuidList.add((String) h.getSourceAsMap().get(Geonet.IndexFieldNames.UUID));
ObjectMapper objectMapper = new ObjectMapper();
for (Hit h : (List<Hit>) searchResponse.hits().hits()) {
uuidList.add((String) objectMapper.convertValue(h.source(), Map.class).get(Geonet.IndexFieldNames.UUID));
}

if (selection != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//=============================================================================
//=== Copyright (C) 2001-2011 Food and Agriculture Organization of the
//=== Copyright (C) 2001-2023 Food and Agriculture Organization of the
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
//=== and United Nations Environment Programme (UNEP)
//===
Expand All @@ -24,11 +24,9 @@
package org.fao.geonet.kernel.datamanager;

import java.io.IOException;
import java.util.Calendar;
import java.util.List;

import org.fao.geonet.domain.AbstractMetadata;
import org.fao.geonet.kernel.search.ISearchManager;
import org.fao.geonet.kernel.search.IndexingMode;
import org.jdom.Element;
import org.springframework.data.jpa.domain.Specification;
Expand Down Expand Up @@ -65,11 +63,6 @@ public interface IMetadataIndexer {
*/
int batchDeleteMetadataAndUpdateIndex(Specification<? extends AbstractMetadata> specification) throws Exception;

/**
* Search for all records having XLinks (ie. indexed with _hasxlinks flag), clear the cache and reindex all records found.
*/
void rebuildIndexXLinkedMetadata(ServiceContext context) throws Exception;

/**
* Reindex all records in current selection.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,31 +200,6 @@ public int batchDeleteMetadataAndUpdateIndex(Specification<? extends AbstractMet
return metadataToDelete.size();
}

@Override
/**
* Search for all records having XLinks (ie. indexed with _hasxlinks flag),
* clear the cache and reindex all records found.
*/
public synchronized void rebuildIndexXLinkedMetadata(final ServiceContext context) throws Exception {

// get all metadata with XLinks
Set<Integer> toIndex = searchManager.getDocsWithXLinks();

if (Log.isDebugEnabled(Geonet.DATA_MANAGER))
Log.debug(Geonet.DATA_MANAGER, "Will index " + toIndex.size() + " records with XLinks");
if (toIndex.size() > 0) {
// clean XLink Cache so that cache and index remain in sync
Processor.clearCache();

ArrayList<String> stringIds = new ArrayList<String>();
for (Integer id : toIndex) {
stringIds.add(id.toString());
}
// execute indexing operation
batchIndexInThreadPool(context, stringIds);
}
}

/**
* Reindex all records in current selection.
*/
Expand Down Expand Up @@ -350,9 +325,9 @@ public void indexMetadata(final String metadataId,
List<Attribute> xlinks = Processor.getXLinks(md);
if (xlinks.size() > 0) {
fields.put(Geonet.IndexFieldNames.HASXLINKS, true);
StringBuilder sb = new StringBuilder();
for (Attribute xlink : xlinks) {
fields.put(Geonet.IndexFieldNames.XLINK, xlink.getValue());
fields.put(Geonet.IndexFieldNames.XLINK, xlink.getValue().replaceAll("local://srv/api/registries/entries/(.*)\\?.*", "$1"));
}
Processor.detachXLink(md, getServiceContext());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1342,8 +1342,8 @@ public boolean isValid(Integer id) {
}

boolean hasReferencingMetadata(ServiceContext context, AbstractMetadata metadata) throws Exception {
StringBuilder query = new StringBuilder(String.format("xlink:*%s*", metadata.getUuid()));
return this.searchManager.query(query.toString(), null, 0, 0).getHits().getTotalHits().value > 0;
StringBuilder query = new StringBuilder(String.format("xlink:\"%s\"", metadata.getUuid()));
return this.searchManager.query(query.toString(), null, 0, 0).hits().total().value() > 0;
}

}
10 changes: 6 additions & 4 deletions core/src/main/java/org/fao/geonet/kernel/mef/MEF2Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@

package org.fao.geonet.kernel.mef;

import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.search.Hit;
import com.fasterxml.jackson.databind.ObjectMapper;
import jeeves.server.context.ServiceContext;
import org.apache.commons.io.FileUtils;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.SearchHit;
import org.fao.geonet.Constants;
import org.fao.geonet.GeonetContext;
import org.fao.geonet.ZipUtil;
Expand Down Expand Up @@ -137,8 +138,9 @@ public static Path doExport(ServiceContext context, Set<String> uuids,
String mdSchema = null, mdTitle = null, mdAbstract = null, isHarvested = null;
MetadataType mdType = null;

SearchHit[] hits = result.getHits().getHits();
final Map<String, Object> source = hits[0].getSourceAsMap();
List<Hit> hits = result.hits().hits();
ObjectMapper objectMapper = new ObjectMapper();
final Map<String, Object> source = objectMapper.convertValue(hits.get(0).source(), Map.class);
mdSchema = (String) source.get(Geonet.IndexFieldNames.SCHEMA);
mdTitle = (String) source.get(Geonet.IndexFieldNames.RESOURCETITLE);
mdAbstract = (String) source.get(Geonet.IndexFieldNames.RESOURCEABSTRACT);
Expand Down
Loading
Loading