Skip to content
This repository was archived by the owner on Sep 2, 2020. It is now read-only.
This repository was archived by the owner on Sep 2, 2020. It is now read-only.

Sorting by text field does not work #33

Open
@mhoffa

Description

@mhoffa

Hello everybody.

I'm trying to sort by field title but the result is always the same,

tried such requests:
http://127.0.0.1:8000/api/v1/search/?ordering=title.raw
http://127.0.0.1:8000/api/v1/search/?ordering=-title.raw

for other fields (score or created), sorting works, what can be wrong?

I have a python 2.7.10 and django-rest-elasticsearch 0.4

search_indexes.py

class BlogIndex(DocType):
  id = Integer()
  title = Text(fields={'raw': Keyword()}, fielddata=True)
  score = Integer()
  created = Date(default_timezone=settings.TIME_ZONE)

  Class Meta:
      index = 'blog'

views.py

class SearchView(es_views.ListElasticAPIView):
    es_client = settings.ES_CLIENT
    es_model = BlogIndex

    es_filter_backends = (
      es_filters.ElasticFieldsFilter,
      es_filters.ElasticFieldsRangeFilter,
      es_filters.ElasticSearchFilter,
      es_filters.ElasticOrderingFilter,
  )

  es_filter_fields = (
      es_filters.ESFieldFilter('score', 'scores'),
  )

  es_ordering_fields = (
      'score',
      'created',
      ("title.raw", "title"),
  )

  es_ordering = '-created'

  es_range_filter_fields = (
      es_filters.ESFieldFilter('created', 'created'),
  )

  es_search_fields = (
      'title',
      'scores',
  )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions