Migration: Indexing Changes

Breaking changes in index definition

Regardless of the data migration strategy you have chosen, you might get warnings complaining about an inability to import some indexes.

This is due to breaking changes to index definitions and requires a manual change.

LoadDocument

LoadDocument requires a second argument which is a collection name of the loaded document.

3.x
from doc in doc.Orders
let company = LoadDocument(doc.Company)
select new 
{
    CompanyName: company.Name
}
4.0
from doc in doc.Orders
let company = LoadDocument(doc.Company, "Companies")
select new 
{
    CompanyName: company.Name
}

Spatial Field Creation

AbstractIndexCreationTask.SpatialGenerate and SpatialIndex.Generate should be replaced with CreateSpatialField. In addition, you can define your own field name and use it when querying.

There are also the following changes:

  • No support for GeoJSON and other non-standard formats
  • No support for spatial clustering
3.x
from b in docs.Places
select new {
 _ = AbstractIndexCreationTask.SpatialGenerate(
                            (double?)b.Latitude, 
                            (double?)b.Longitude)
}
4.0
from b in docs.Places
select new {
    Coordinates = CreateSpatialField(
                        (double?)b.Latitude, 
                        (double?)b.Longitude)
}

AsDocument

AsDocument call should be replaced by AsJson method.

3.x
from user in users
select new
{
    Query = AsDocument(user).Select(x => x.Value)
};
4.0
from user in users
select new
{
    Query = AsJson(user).Select(x => x.Value)
};

DynamicList

Any occurrence of new Raven.Abstractions.Linq.DynamicList() should be removed from an index definition.

Built-in Indexes

Raven/DocumentsByEntityName and Raven/ConflictDocuments are no longer necessary and are intentionally skipped during the import.

Auto Indexes

The query optimizer and auto indexing mechanisms have significantly changed in RavenDB 4.0. Auto indexes imported from 3.x will get Legacy/ prefix added to their names. You should consider removing the legacy ones and let RavenDB create new auto indexes from scratch.

Another important breaking change is that dynamic queries (not specifying an index name) are only handled by auto indexes. The query optimizer doesn't take into account the static indexes when it determines what index should be used to handle a query.

The legacy auto indexes won't be used to satisfy dynamic queries because they will be imported as the static ones.

Plugins & Extensions

Compilation Extensions

As a replacement for Compilation Extensions you can use the Additional Sources feature. It allows you to write your own C# code and use it during indexing. The code is attached to the index definition.

You can also deploy custom DLLs next to RavenDB binaries and reference them in your extensions.

Custom Analyzers

Please read our dedicated article about using non-default or custom analyzers.

Analyzer Generators

Analyzer generators aren't supported.

Do you need any help with Migration?