Updating an Index

33 views
Skip to first unread message

Eniep Yrekcaz

unread,
Jan 9, 2013, 5:58:39 PM1/9/13
to rav...@googlegroups.com
I work in an environment which has dev, qa, pre and prod servers. I would like to know if there is an automated way I could update an index. 

For example, I prototyped a product utilizing RavenDB. 
It has a couple of documents:
Account{
   int ID,
   string Name,
   string Phone
}
Contact{
    int ID,
    string LastName,
    string Phone
}
and an Index
SearchDocs
docs.Accounts
.Select(account => new () { Content = new System.Object []{account.Name, account.Phone})
Content: Analyzed

docs.Contacts
.Select(contact => new () { Content = new System.Object []{contact.LastName, contact.Phone})
Content: Analyzed

I created the index through the studio initially. Now that it seems as though we are going ahead with this project, the actual business requirements are to have the documents contain more fields(LastName for contact, Address for account) and then allow the user to search on all the field values. Is there a way to update the index via C# to include those fields as part of the Content so that I could more easily push the changes up through the environments?

Would I use UpdateByIndex? If so, are there any examples how to use it?

Chris Marisic

unread,
Jan 10, 2013, 3:46:50 PM1/10/13
to rav...@googlegroups.com
      IndexCreation.CreateIndexes(typeof(MyIndex).Assembly, documentStore);

You can run this to create or update indexes, if there are no index changes, it's a NO-OP.

In debug we have this automatically, in release we only allow it to be invoked by an admin with specific action, never just by deployment and site load.

Eniep Yrekcaz

unread,
Jan 10, 2013, 4:20:20 PM1/10/13
to rav...@googlegroups.com
Ok, so that will work to add or update? I'm pretty sure I tried that in a previous version and if the Index already existed on the server I would receive an error.
Thanks, I'll give it a try.

Chris Marisic

unread,
Jan 10, 2013, 4:34:06 PM1/10/13
to rav...@googlegroups.com
I've used this method since Raven 100 series.

With Raven 960 is when I stopped it from automatically being executed on app start to be an admin invoked operation only.
Reply all
Reply to author
Forward
0 new messages