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

Sorting by text field does not work #33

Open
mhoffa opened this issue Apr 18, 2018 · 2 comments
Open

Sorting by text field does not work #33

mhoffa opened this issue Apr 18, 2018 · 2 comments

Comments

@mhoffa
Copy link

mhoffa commented Apr 18, 2018

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',
  )
@dmvass
Copy link
Collaborator

dmvass commented Apr 25, 2018

@mhoffa
Copy link
Author

mhoffa commented Apr 25, 2018

Yes, I tried it too, But sorting did not work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants