Working with an index handler with the XML format

Now let's try to add some content to our index using the XML format. Open the Postman tool and add the URL http://localhost:8983/solr/gettingstarted/update, as shown in the following screenshot:

Note that we have selected the method type to POST. You also need to add a request header, Content-Type, to text/xml. Most of this can be done in Postman as we just select values from the dropdown, as shown previously.

Now switch to the Body tab and add the following content:

<add>
<doc>
<field name="title">Harry Potter and Prisoner of
Azkaban</field>
<field name="author">J.K. Rowling</field>
</doc>
</add>

For adding any documents to index, the XML schema should have the following elements:

  • <add>: Specifies that the operation we are going to perform will add one or more documents
  • <doc>: This has fields that make up the whole document
  • <field>: Specifies each field to be added for the document

Once you are done with the aforementioned steps, click on the Send button in Postman. If everything goes right, you should see the following response:

This indicates that the document has been successfully added to the index. In order to verify the documents, you can go to the Solr admin console in the browser, select gettingstarted, and then navigate to the Query section, as follows:

Once you are on the previous page, click on the Execute Query button available at the very bottom of the page. You should see something like this:

{
"responseHeader":{
"zkConnected":true,
"status":0,
"QTime":18,
"params":{
"q":"*:*",
"_":"1514434725886"}},
"response":{"numFound":3,"start":0,"maxScore":2.0,"docs":[
{
"title":["Harry Potter and Chamber of Secrets"],
"author":["J.K. Rowling"],
"id":"0bb62d53-20d0-4df2-a385-c08b8658dc28",
"title_str":["Harry Potter and Chamber of Secrets"],
"author_str":["J.K. Rowling"],
"_version_":1587892939487444992},
{
"title":["Harry Potter and Prisoner of Azkaban"],
"author":["J.K. Rowling"],
"id":"401f8336-88d9-478c-93a2-2de070188a3d",
"title_str":["Harry Potter and Prisoner of Azkaban"],
"author_str":["J.K. Rowling"],
"_version_":1587999318593241088},
{
"title":["Harry Potter and Philosophers Stone"],
"author":["J.K. Rowling"],
"id":"dcbfd369-2a4b-4e9d-9713-1af373849438",
"title_str":["Harry Potter and Philosophers Stone"],
"author_str":["J.K. Rowling"],
"_version_":1587892903981613056}]
}}

As you can see, the document with the title Harry Potter and Prisoner of Azkaban is added to the index. I had previously added some other documents, so that's why you are seeing two additional entries.

Now let's try to delete some documents from the index. Open Postman and just replace the content with the following:

<delete>
<id>0bb62d53-20d0-4df2-a385-c08b8658dc28</id>
<query>title:azkaban</query>
</delete>

In Postman, it will look something like this once executed:

What we have done is deleted a couple of records, one with a query where the title is Azkaban and one with the ID 0bb62d53-20d0-4df2-a385-c08b8658dc28. In order to verify this, go to the admin console and click on the Execute Query button once again:

As you can see, there is only one entry now as the other two entries have been deleted.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.103.61