Skip to main content

πŸ‘ Testing the Search Index

Now that you have a search index, you can test it out.

From the list of indexes, look for the Query button.

The Query button from the list of indexes

Search Tester​

By using the Query button above, you will open the Search Tester. In the field, enter the word:

cooking

Look at the results you get.

The Search Tester

You can see that you get a list of books back including:

  • Pennsylvania Dutch Cooking: A Mennonite Community Cookbook.
  • Semi-Homemade Cooking: Quick, Marvelous Meals and Nothing is Made from…
  • Cookin' Cajun Cooking School Cookbook - Creole and Cajun Cuisine from…

All those results match the word cooking. Notice how capitalization doesn't matter. Neither does the placement of the word in the title. The search index is smart enough to find the word cooking in all those titles.

Already, you are providing a better experience to your developers.

Searching only the title​

This is great. However, this search query is searching the entire document. There might be some cases where that works for you, but in most cases, you'll likely want to limit this search only to the fields that matter. In this case, let's change it to only search the title.

In the Search Tester, click on the Edit $search query button, next to the green Search button.

This will open up the query editor.

The Edit $search query button

Notice that the path property currently shows *. This means that it will search the entire document. Try to change the search to only search the title field.

tip

You can find more information about how to construct a query path in the Search documentation.

Click here to see the answer
[
{
$search: {
index: "fulltextsearch",
text: {
query: "cooking",
path: ["title"]
}
}
}
]

You will see the same results but ordered differently. This has to do with relevancy, but we'll cover that in a later section.