RaZzLe
RaZzLe

Reputation: 2128

Updating Solr Document Results Duplicate Versions

In my .net core project I'm updating a SOLR document via the below method:

    public Task<HttpResponseMessage> UpdateDocumentAsync(List<SolrDocument> SolrDocument, CancellationToken cancellationToken)
    {
        _request.Method = HttpMethod.Post;

        _request.RequestUri = new Uri($"{this._baseUri}/update?overwrite=true&commitWithin=2000&wt=json");

        var content = new StringContent(JsonConvert.SerializeObject(SolrDocument), Encoding.UTF8, "application/json");

        _request.Content = content;

        return base.SendAsync(_request, cancellationToken);
    }

As you can see, I'm even stating overwrite=true command on my update URL. Before posting this question I run into other similar topics and saw that defining a unique field on SOLR schema will help, otherwise SOLR would never know whether I'm updating and existing document. Then I checked my schema and saw that a unique field was already defined. I'm sharing necessary parts of my schema below:

<?xml version="1.0" encoding="UTF-8" ?>
    <schema name="My Project Solr 7.2.0 (stable version) Instance" version="1.6">
    <field name="id" type="string" indexed="true" stored="true" required="true" />
    <field name="_version_" type="long" indexed="true" stored="true"/>
    <!-- tons of other fields -->
    <uniqueKey>id</uniqueKey>

Thus, I cannot able to figure out what the real problem is. When I update a doc in SOLR, another doc with the same id but different _version_ is created. After that, when I send a \select request with id:12345 query, SOLR lists one document BUT sometimes it brings the updated document and sometimes not-updated document.

To make it clear, SOLR never list two documents with the same id, but older version of the same document still continue to exists in the SOLR. Thus, this results with a super confusion on the application.

FYI, I have updated the schema recently by adding some additional fields. In the problem I have described above, I cannot see my new fields on the old document (which is super normal), but I can see my new fields on the other updated document with different _version_ (but same id). Is this the case? If so, how can I force SOLR to dispose the current doc which do not consist the new fields while updating?

Thanks in advance.

Upvotes: 0

Views: 136

Answers (1)

RaZzLe
RaZzLe

Reputation: 2128

It turns out to be my current core is different than the document's original core thus ended up in indexing it my current core with a new _verion_.

Upvotes: 0

Related Questions