Dynamic Mappings / Settings with Compass

One of the upcoming Compass 2.1 M1 features include a much requested feature by users which is the ability to dynamically remove and add mappings using the Compass instance. So, Compass instance now allows to get its internal ComapssConfiguration object and change it dynamically (not just mappings, but other settings as well). One changes, Compass#rebuild() should be called in order to take the changes into account. Here is an example:

1
2
3
4
5
Compass compass = // create the compass instance
 
compass.getConfig().addClass(NewClass.class);
compass.getConfig().removeMappingByClass(OldClass.class);
compass.rebuild();

From now on, any operations on the new Compass instance will use the updated mappings (and optional settings). Underneath, Compass shuts down the “old Compass instance” gracefully (waiting for current open sessions to be closed).

One Response to “Dynamic Mappings / Settings with Compass”

  1. KimchyBlog » Blog Archive » Compass 2.1.0 M1 Released Says:

    […] a much improved XSEM support (namespace xpath, better stax integration, jdom integration), Dynamic mappings removal and additions, JSEM - JSON to Search Engine Mapping support, and Collocated integration and distributed search […]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>