6

Is there any reason to set additional fields with indexed=False into SearchIndex?

Documentation mentioned that additional fields should be defined for filtering or ordering results. By default SearchIndex has indexed=True, so what happens if I set indexed=False?

Will the data still be stored on index but not be indexed? What happens if I'd set stored=False?

How does it works?

Thanks

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
Fibio
  • 151
  • 3

1 Answers1

4

By default, all fields in Haystack are both indexed (searchable by the engine) and stored (retained by the engine and presented in the results). By using a stored field, you can store commonly used data in such a way that you don’t need to hit the database when processing the search result to get more information. You get this advantage if you specify indexed=True and stored=True.

If you specify only indexed=True, you will be hitting the database when processing the search result to get additional information not available in the index.

The purpose of indexed=False is to cater for the scenario where you want a rendered field to follow a pre-rendered template during the indexing process. A good example is illustrated here - https://django-haystack.readthedocs.org/en/latest/searchindex_api.html#stored-indexed-fields

Calvin Cheng
  • 35,640
  • 39
  • 116
  • 167