fix #2025 replace version with seq_no and primary_term
This commit is contained in:
parent
b599694571
commit
e4c778d3da
10 changed files with 77 additions and 17 deletions
|
@ -239,6 +239,8 @@ public class SearchService {
|
|||
|
||||
docMap.put(fessConfig.getIndexFieldId(), hit.getId());
|
||||
docMap.put(fessConfig.getIndexFieldVersion(), hit.getVersion());
|
||||
docMap.put(fessConfig.getIndexFieldSeqNo(), hit.getSeqNo());
|
||||
docMap.put(fessConfig.getIndexFieldPrimaryTerm(), hit.getPrimaryTerm());
|
||||
return docMap;
|
||||
}, cursor);
|
||||
}
|
||||
|
|
|
@ -239,7 +239,8 @@ public class AdminSearchlistAction extends FessAdminAction {
|
|||
getDoc(form).ifPresent(entity -> {
|
||||
form.doc = fessConfig.convertToEditableDoc(entity);
|
||||
form.id = (String) entity.remove(fessConfig.getIndexFieldId());
|
||||
form.version = (Long) entity.remove(fessConfig.getIndexFieldVersion());
|
||||
form.seqNo = (Long) entity.remove(fessConfig.getIndexFieldSeqNo());
|
||||
form.primaryTerm = (Long) entity.remove(fessConfig.getIndexFieldPrimaryTerm());
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), () -> asListHtml());
|
||||
});
|
||||
|
@ -291,9 +292,11 @@ public class AdminSearchlistAction extends FessAdminAction {
|
|||
final String oldId = (String) entity.get(fessConfig.getIndexFieldId());
|
||||
if (!newId.equals(oldId)) {
|
||||
entity.put(fessConfig.getIndexFieldId(), newId);
|
||||
final Long version = (Long) entity.remove(fessConfig.getIndexFieldVersion());
|
||||
if (version != null && oldId != null) {
|
||||
fessEsClient.delete(index, oldId, version);
|
||||
entity.remove(fessConfig.getIndexFieldVersion());
|
||||
final Long seqNo = (Long) entity.remove(fessConfig.getIndexFieldSeqNo());
|
||||
final Long primaryTerm = (Long) entity.remove(fessConfig.getIndexFieldPrimaryTerm());
|
||||
if (seqNo != null && primaryTerm != null && oldId != null) {
|
||||
fessEsClient.delete(index, oldId, seqNo, primaryTerm);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ public class EditForm extends CreateForm {
|
|||
public String id;
|
||||
|
||||
@ValidateTypeFailure
|
||||
public Long version;
|
||||
public Long seqNo;
|
||||
|
||||
@ValidateTypeFailure
|
||||
public Long primaryTerm;
|
||||
}
|
||||
|
|
|
@ -163,9 +163,11 @@ public class ApiAdminSearchlistAction extends FessApiAdminAction {
|
|||
final String oldId = (String) entity.get(fessConfig.getIndexFieldId());
|
||||
if (!newId.equals(oldId)) {
|
||||
entity.put(fessConfig.getIndexFieldId(), newId);
|
||||
final Number version = (Number) entity.remove(fessConfig.getIndexFieldVersion());
|
||||
if (version != null && oldId != null) {
|
||||
fessEsClient.delete(index, oldId, version.longValue());
|
||||
entity.remove(fessConfig.getIndexFieldVersion());
|
||||
final Number seqNo = (Number) entity.remove(fessConfig.getIndexFieldSeqNo());
|
||||
final Number primaryTerm = (Number) entity.remove(fessConfig.getIndexFieldPrimaryTerm());
|
||||
if (seqNo != null && primaryTerm != null && oldId != null) {
|
||||
fessEsClient.delete(index, oldId, seqNo, primaryTerm);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -798,6 +798,8 @@ public class FessEsClient implements Client {
|
|||
final Map<String, Object> docMap = new HashMap<>(source);
|
||||
docMap.put(fessConfig.getIndexFieldId(), hit.getId());
|
||||
docMap.put(fessConfig.getIndexFieldVersion(), hit.getVersion());
|
||||
docMap.put(fessConfig.getIndexFieldSeqNo(), hit.getSeqNo());
|
||||
docMap.put(fessConfig.getIndexFieldPrimaryTerm(), hit.getPrimaryTerm());
|
||||
return docMap;
|
||||
}
|
||||
final Map<String, DocumentField> fields = hit.getFields();
|
||||
|
@ -807,6 +809,8 @@ public class FessEsClient implements Client {
|
|||
.collect(Collectors.toMap(e -> e.getKey(), e -> (Object) e.getValue().getValues()));
|
||||
docMap.put(fessConfig.getIndexFieldId(), hit.getId());
|
||||
docMap.put(fessConfig.getIndexFieldVersion(), hit.getVersion());
|
||||
docMap.put(fessConfig.getIndexFieldSeqNo(), hit.getSeqNo());
|
||||
docMap.put(fessConfig.getIndexFieldPrimaryTerm(), hit.getPrimaryTerm());
|
||||
return docMap;
|
||||
}
|
||||
return null;
|
||||
|
@ -1151,7 +1155,9 @@ public class FessEsClient implements Client {
|
|||
@SuppressWarnings("unchecked")
|
||||
final Map<String, Object> source = obj instanceof Map ? (Map<String, Object>) obj : BeanUtil.copyBeanToNewMap(obj);
|
||||
final String id = (String) source.remove(fessConfig.getIndexFieldId());
|
||||
final Number version = (Number) source.remove(fessConfig.getIndexFieldVersion());
|
||||
source.remove(fessConfig.getIndexFieldVersion());
|
||||
final Number seqNo = (Number) source.remove(fessConfig.getIndexFieldSeqNo());
|
||||
final Number primaryTerm = (Number) source.remove(fessConfig.getIndexFieldPrimaryTerm());
|
||||
IndexResponse response;
|
||||
try {
|
||||
if (id == null) {
|
||||
|
@ -1165,8 +1171,11 @@ public class FessEsClient implements Client {
|
|||
final IndexRequestBuilder builder =
|
||||
client.prepareIndex().setIndex(index).setId(id).setSource(new DocMap(source))
|
||||
.setRefreshPolicy(RefreshPolicy.IMMEDIATE).setOpType(OpType.INDEX);
|
||||
if (version != null && version.longValue() > 0) {
|
||||
builder.setVersion(version.longValue());
|
||||
if (seqNo != null) {
|
||||
builder.setIfSeqNo(seqNo.longValue());
|
||||
}
|
||||
if (primaryTerm != null) {
|
||||
builder.setIfPrimaryTerm(primaryTerm.longValue());
|
||||
}
|
||||
response = builder.execute().actionGet(fessConfig.getIndexIndexTimeout());
|
||||
}
|
||||
|
@ -1177,16 +1186,23 @@ public class FessEsClient implements Client {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean delete(final String index, final String id, final long version) {
|
||||
public boolean delete(final String index, final String id) {
|
||||
return delete(index, id, null, null);
|
||||
}
|
||||
|
||||
public boolean delete(final String index, final String id, final Number seqNo, final Number primaryTerm) {
|
||||
try {
|
||||
final DeleteRequestBuilder builder = client.prepareDelete().setIndex(index).setId(id).setRefreshPolicy(RefreshPolicy.IMMEDIATE);
|
||||
if (version > 0) {
|
||||
builder.setVersion(version);
|
||||
if (seqNo != null) {
|
||||
builder.setIfSeqNo(seqNo.longValue());
|
||||
}
|
||||
if (primaryTerm != null) {
|
||||
builder.setIfPrimaryTerm(primaryTerm.longValue());
|
||||
}
|
||||
final DeleteResponse response = builder.execute().actionGet(ComponentUtil.getFessConfig().getIndexDeleteTimeout());
|
||||
return response.getResult() == Result.DELETED;
|
||||
} catch (final ElasticsearchException e) {
|
||||
throw new FessEsClientException("Failed to delete: " + index + "/" + id + "/" + version, e);
|
||||
throw new FessEsClientException("Failed to delete: " + index + "/" + id + "@" + seqNo + ":" + primaryTerm, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ public class IndexingHelper {
|
|||
|
||||
public boolean deleteDocument(final FessEsClient fessEsClient, final String id) {
|
||||
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
return fessEsClient.delete(fessConfig.getIndexDocumentUpdateIndex(), id, 0);
|
||||
return fessEsClient.delete(fessConfig.getIndexDocumentUpdateIndex(), id);
|
||||
}
|
||||
|
||||
public long deleteDocumentByUrl(final FessEsClient fessEsClient, final String url) {
|
||||
|
|
|
@ -305,8 +305,10 @@ public class QueryHelper {
|
|||
fessConfig.getIndexFieldLastModified(), //
|
||||
fessConfig.getIndexFieldMimetype(), //
|
||||
fessConfig.getIndexFieldParentId(), //
|
||||
fessConfig.getIndexFieldPrimaryTerm(), //
|
||||
fessConfig.getIndexFieldRole(), //
|
||||
fessConfig.getIndexFieldSegment(), //
|
||||
fessConfig.getIndexFieldSeqNo(), //
|
||||
fessConfig.getIndexFieldSite(), //
|
||||
fessConfig.getIndexFieldTimestamp(), //
|
||||
fessConfig.getIndexFieldUrl(), //
|
||||
|
|
|
@ -420,6 +420,12 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
/** The key of the configuration. e.g. _version */
|
||||
String INDEX_FIELD_VERSION = "index.field.version";
|
||||
|
||||
/** The key of the configuration. e.g. _seq_no */
|
||||
String INDEX_FIELD_seq_no = "index.field.seq_no";
|
||||
|
||||
/** The key of the configuration. e.g. _primary_term */
|
||||
String INDEX_FIELD_primary_term = "index.field.primary_term";
|
||||
|
||||
/** The key of the configuration. e.g. lang */
|
||||
String INDEX_FIELD_LANG = "index.field.lang";
|
||||
|
||||
|
@ -2697,6 +2703,20 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
*/
|
||||
String getIndexFieldVersion();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'index.field.seq_no'. <br>
|
||||
* The value is, e.g. _seq_no <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
*/
|
||||
String getIndexFieldSeqNo();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'index.field.primary_term'. <br>
|
||||
* The value is, e.g. _primary_term <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
*/
|
||||
String getIndexFieldPrimaryTerm();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'index.field.lang'. <br>
|
||||
* The value is, e.g. lang <br>
|
||||
|
@ -6715,6 +6735,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
return get(FessConfig.INDEX_FIELD_VERSION);
|
||||
}
|
||||
|
||||
public String getIndexFieldSeqNo() {
|
||||
return get(FessConfig.INDEX_FIELD_seq_no);
|
||||
}
|
||||
|
||||
public String getIndexFieldPrimaryTerm() {
|
||||
return get(FessConfig.INDEX_FIELD_primary_term);
|
||||
}
|
||||
|
||||
public String getIndexFieldLang() {
|
||||
return get(FessConfig.INDEX_FIELD_LANG);
|
||||
}
|
||||
|
@ -8652,6 +8680,8 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
defaultMap.put(FessConfig.INDEX_FIELD_doc_id, "doc_id");
|
||||
defaultMap.put(FessConfig.INDEX_FIELD_ID, "_id");
|
||||
defaultMap.put(FessConfig.INDEX_FIELD_VERSION, "_version");
|
||||
defaultMap.put(FessConfig.INDEX_FIELD_seq_no, "_seq_no");
|
||||
defaultMap.put(FessConfig.INDEX_FIELD_primary_term, "_primary_term");
|
||||
defaultMap.put(FessConfig.INDEX_FIELD_LANG, "lang");
|
||||
defaultMap.put(FessConfig.INDEX_FIELD_has_cache, "has_cache");
|
||||
defaultMap.put(FessConfig.INDEX_FIELD_last_modified, "last_modified");
|
||||
|
|
|
@ -235,6 +235,8 @@ index.field.url=url
|
|||
index.field.doc_id=doc_id
|
||||
index.field.id=_id
|
||||
index.field.version=_version
|
||||
index.field.seq_no=_seq_no
|
||||
index.field.primary_term=_primary_term
|
||||
index.field.lang=lang
|
||||
index.field.has_cache=has_cache
|
||||
index.field.last_modified=last_modified
|
||||
|
|
|
@ -29,7 +29,8 @@
|
|||
<la:hidden property="q" />
|
||||
<c:if test="${crudMode==2}">
|
||||
<la:hidden property="id" />
|
||||
<la:hidden property="version" />
|
||||
<la:hidden property="seqNo" />
|
||||
<la:hidden property="primaryTerm" />
|
||||
</c:if>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
|
Loading…
Add table
Reference in a new issue