Goal:
Dynamically assign documents to a collection, based on the needs of a particular document or indexing request.
If you choose to use a datasource for indexing, that datasource has an associated index pipeline as well as an associated collection to which the index pipeline outputs. By default, datasources are contained within a collection and cannot be accessed from outside collections.
Some scenarios warrant the need for Fusion to assign a document to a collection based on data within that document.
Environment:
Fusion 4.x or Fusion 5.x
Solution and Guide:
An index profile is also a simple way to use one index pipeline for multiple collections, without any one collection "owning" the pipeline. Then, you can choose to assign documents to a collection without all documents sent to that index profile going into that collection.
Associating an index profile with an index pipeline, or an index pipeline and a collection, is simply a mapping used for reference.
In the event that you'd like to recycle a datasource and use it across multiple collections, you can use the JavaScript Index Stage in the Fusion index pipeline to reassign the collection which the pipeline will output to.
The instructions below set up an index profile POST documents directly to the endpoint opened up by the index profile. The index profile then sends the documents to the index pipeline where there is a JavaScript index stage that alters the `collection` property programmatically. Note that you could use a conditional script to output to a certain collection based on whichever criteria and logic you use.
Here are the instructions for recreating this example:
1. Create a an index profile - choose the pipeline which you will be using to index to all collections
2. in that index pipeline, add a javascript index stage with the followingvar new_collection = ctx.setProperty('collection','COLLECTION_NAMEl');
replace COLLECTION_NAME with the collection to which you'd like to index. You can then use logic, such as reading a particular field for a document, to make the determination of which collection to assign the document to.
3. Save the index pipeline
4. Send documents to the index profile endpoint and verify that they index to the collection that you specified.
Comments
0 comments
Please sign in to leave a comment.