Hi guys,
Great project :)
I am however in a bit of a pickle. Ive setup ElasticSearch, Django Haystack and drf-haystack in my project and it mostly seems to work great. Ive tried a lot of things and I am completely stumped so I am hoping someone here might have an idea whats going on :)
But when I execute this query (submission is a datetime):
?submission__lt=2016-04-01
I get 0 results and the following error in my PyCharm console:
RequestError: TransportError(400, u'SearchPhaseExecutionException[Failed to execute phase [query_fetch], all shards failed; shardFailures {[AQ0uPhhWQlyk026CpVP89w][haystack][0]: SearchParseException[[haystack][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"filtered": {"filter": {"terms": {"django_ct": ["model.modelitem", "model.modelrepository", "model.modelfamily"]}}, "query": {"query_string": {"fuzzy_max_expansions": 50, "auto_generate_phrase_queries": true, "default_operator": "AND", "analyze_wildcard": true, "query": "(submission:({* TO \\"2016\\\\-04\\\\-01\\"}) AND submission:({* TO \\"2016\\\\\\\\\\\\-04\\\\\\\\\\\\-01\\"}))", "default_field": "text", "fuzzy_min_sim": 0.5}}}}, "from": 0, "highlight": {"fields": {"text": {"store": "yes"}}}}]]]; nested: ElasticsearchParseException[failed to parse date field [2016\\-04\\-01], tried both date format [dateOptionalTime], and timestamp number]; nested: IllegalArgumentException[Invalid format: "2016\\-04\\-01" is malformed at "\\-04\\-01"]; }]')
But when I execute
?submission__gt=2016-04-01
It returns the expected results/documents and no error is displayed
Setup:
OS: Ubuntu 15.10
Python: 2.7.10
Elasticsearch: 1.6.2
From requirements.txt:
Django: 1.9.1
Haystack: 2.5.dev0 (Else it doesnt work with Django 1.9)
drf-haystack==1.5.6
elasticsearch==1.9.0
I’ve tried downgrading Django to 1.8 and Haystack to 2.4 but I had the same error. I’ve tried a few other combinations of versions but there is always something that breaks :) Usually the same error or facet search didnt work.
I ran the same query using the python shell (using just haystack):
>>> lt_results = SearchQuerySet().filter(submission__lt=datetime.date(2016, 4, 1))
>>> lt_results.count()
6
Which led me to believe this has something to do with drf-haystack :) Any help would be greatly appreciated, I am completely stumped on how to fix this.
The faceted search works for all fields, apart from the submission field. When I click the narrow_url (that has a count of 6) and execute that query, it returns 0 results. Maybe that is related somehow?
Well here is my code if that helps:
urls.py:
router = routers.DefaultRouter()
router.register("model/search",ModelItemFacetViewSet, base_name="model-search")
router.register("^search/facets/$", ModelItemFacetViewSet, base_name="model-search-facet")
urlpatterns =(
url(r"", include(router.urls)),
)
views.py:
class ModelItemFacetViewSet(HaystackViewSet):
index_classes = [ModelItemIndex, ModelFamilyIndex, ModelRepositoryIndex]
# This will be used to filter and serialize regular queries as well
# as the results if the `facet_serializer_class` has the
# `serialize_objects = True` set.
serializer_class = ModelItemSerializer
filter_backends = [HaystackHighlightFilter, HaystackAutocompleteFilter]
# This will be used to filter and serialize faceted results
facet_serializer_class = ModelItemFacetSerializer # See example above!
facet_filter_backends = [HaystackFacetFilter] # This is the default facet filter, and
# can be left out.
search_indexes.py:
class SpecimenIndex(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
name = indexes.CharField(model_attr='name')
submission = indexes.DateTimeField(model_attr='submission', faceted=True)
type = indexes.CharField(model_attr='type', null=True)
abbreviation = indexes.CharField(model_attr='abbreviation', null=True)
class Meta:
abstract = True
def get_model(self):
return Specimen
def index_queryset(self, using=None):
return self.get_model().objects.all()
class ReportableIndex(SpecimenIndex):
class Meta:
abstract = True
def get_model(self):
return Reportable
def index_queryset(self, using=None):
return self.get_model().objects.all()
class ReviewableIndex(ReportableIndex):
id = indexes.CharField(model_attr='id')
life_cycle_phase = indexes.CharField(model_attr='life_cycle_phase', null=True)
model_category = indexes.CharField(model_attr='model_category', faceted=True)
file_size = indexes.CharField(model_attr='generated_information__file_size', faceted=True)
file_format = indexes.CharField(model_attr='generated_information__file_format', faceted=True)
number_of_downloads = indexes.CharField(model_attr='generated_information__number_of_downloads', faceted=True)
number_of_models = indexes.CharField(model_attr='classification_information__number_of_models', faceted=True)
modeling_language = indexes.CharField(model_attr='classification_information__modeling_language', faceted=True)
tool_vendor = indexes.CharField(model_attr='classification_information__generating_tool__vendor', null=True, faceted=True)
tool_product = indexes.CharField(model_attr='classification_information__generating_tool__product', null=True, faceted=True)
tool_version = indexes.CharField(model_attr='classification_information__generating_tool__version', null=True, faceted=True)
quality = indexes.CharField(model_attr='assessment_information__quality')
completeness = indexes.CharField(model_attr='assessment_information__completeness')
level_of_model = indexes.CharField(model_attr='assessment_information__level_of_model')
uuid = indexes.CharField(model_attr='uuid', null=True)
license = indexes.CharField(model_attr='license__name', null=True, faceted=True)
class Meta:
abstract = True
def get_model(self):
return Reviewable
def index_queryset(self, using=None):
return self.get_model().objects.all()
class GroupableIndex(ReviewableIndex):
parent = indexes.CharField(model_attr='parent', null=True)
class Meta:
abstract = True
def get_model(self):
return Groupable
def index_queryset(self, using=None):
return self.get_model().objects.all()
class ModelItemIndex(GroupableIndex, indexes.Indexable):
def get_model(self):
return ModelItem
def index_queryset(self, using=None):
return self.get_model().objects.all()
class ModelFamilyIndex(GroupableIndex, indexes.Indexable):
def get_model(self):
return ModelFamily
def index_queryset(self, using=None):
return self.get_model().objects.all()
class ModelRepositoryIndex(ReviewableIndex, indexes.Indexable):
def get_model(self):
return ModelRepository
def index_queryset(self, using=None):
return self.get_model().objects.all()
All template _text.txt files look like this (model item, model family and model repository) :
{{object.name}}
{{object.id}}
{{object.submission}}