How to sort with case insensitive in elasticsearch

My index name is data_new

Below is the code to insert into index

test = [   {'id':1,'name': 'Cost Accounting 400', 'professor': ['Bill Cage', 'accounting']},
    { 'id':2,  'name': 'Computer Internals 250', 'professor': ['Gregg Payne', 'engineering']},
    {'id':3,   'name': 'Accounting Info Systems 350',   'professor': ['Bill Cage', 'accounting']},
    {'id':4,'name': 'Tax Accounting 200', 'professor': ['Thomas Baszo', 'finance']},
    {'id':5,'name': 'Capital Markets 350', 'professor': ['Thomas Baszo', 'finance']},
    {'id':6,'name': 'Theatre 410', 'professor': ['Sebastian Hern', 'art']},
    {'id':7,'name': 'Accounting 101', 'professor': ['Thomas Baszo', 'finance']},
    {'id':8,'name': 'Marketing 101', 'professor': ['William Smith', 'finance']},
    {'id':8,'name': 'Anthropology 230', 'professor': ['Devin Cranford', 'history']},
    {'id':10,   'name': 'Computer Science 101',
        'professor': ['Gregg Payne', 'engineering']}]
from elasticsearch import Elasticsearch
import json
es = Elasticsearch()
es.indices.create(index='data_new', ignore=400)
for e in test:
        es.index(index="data_new", body=e, id=e['id'])
search = es.search(index="data_new", body={"from" : 0, "size" : 2,"query": {"match_all": {}}})
search['hits']['hits']

Right now

for input ["a", "b", "B", "C", "c", "A"] the result is : ["A", "B", "C", "a", "b", "c"]

I want output as ["A", "a", "B", "b", "C", "c"]

Expected out

My first Expected output > I need to sort the output with respect to name only in {Case insensitive}. I need to normalise name keyword and sort

I am able to sort only > search = es.search(index="data_new", body={ "sort" : [{"name.keyword" : {"order" : "asc"}}], "from":0, "size":2, "query":{ "match_all":{}}})

How to do the modification on search = es.search(index="data_new", body={"from" : 0, "size" : 2,"query": {"match_all": {}}})

I have updated the code with below search = es.search(index="data_new", body={ "sort" : [{"name.keyword" : {"order" : "asc","normalizer": "case_insensitive"}}], "from":0, "size":2, "query":{ "match_all":{}}}) I got the error

RequestError: RequestError(400, 'x_content_parse_exception', '[1:41] [field_sort] unknown field [normalizer]')

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.