Creating Sitecore Index Part - 2

  Introduction:

In Part-1 we have only created the Index that is in sync with SOLR. In this part we will try to Index only field we want to Index.

Background:

Let us see what we have in our Sitecore tree that will be default indexed after our Part-1 Finished. In our Custom index configuration we have given the path to be indexed as news.

fig.1
fig.2

As we can see from the image above there will be 6 Items indexed (including News item). let us check our Solr for the same.

fig.3

the sample from solr contains information about "Hamirpur news" (check fig.2) , 

1 - Add a Field:
In practical scenario, we will not require all the fields to be indexed, thus, we will try to add selected fields only. For our scenario we will try to add "Abstract information" field only.

fig.4
we need the "Abstract Information" field Id as shown in the above screen short.
We will update the config file of part-1 to only Index the above mentioned Field ID.


fig.5
under configuration tag on we will be adding Document option tag. here wee will first mention not to include all fields, then mention the field ID we want to be as part of index. 

After updating the Config, go to Sitecore site. Go to Control panel and under Index manager, rebuild our custom index.
fig.6
Go to your SORL Url (in my project it is) : https://sc10sc.dev.local:8984/solr/#
(if already running  hit Ctrl + F5 to load it again from server side.)
fig.7
Select custom index in dropdown and then click Query followed by Execute Query.
You will see value are present only to Field ID mentioned in the configuration.

fig.8

2 - Add Multiple Fields:

In Order to add multiple fields just insert another row of <fieldId> tag as shown below. Follow the same process as we did above for adding first field.
fig.9

3 - Add Index based on Template:

Now usually when we follow best practices, we face less problem. But in reality, there are many clients where the best practices are still in developing phase. Thus, in those scenario, we might have items from different templates under same node. the expectation will be to index only items created by specific Template.

Go to your custom Index config file, and add a include tag for Template we want to index.
fig.10
After the change is updated in config file Sitecore App will restart, rebuild your custom Index again.

Go to SOLR (Url as shown above, execute query as shown above.) and you will see only 2 Items are index because those 2 are created using the specified Template.
fig.11
Solr snap short.
fig.12
Conclusion:
In this part we now know how to successfully add Fields (Simple fields) and how we can select based on Template as well.

Comments

Popular posts from this blog

Rebuild XDB indexing Issues

Upgrading from Sitecore 9.3 to 10.3: A Practical Guide

Sitecore Bulk Uploading Data Between Identical Databases