Facet sort does not work?

export function buildFacetConfigFromConfig() {
  const config = getConfig();

  const facets = (config.facets || []).reduce((acc, n) => {
    acc = acc || {};
    acc[n] = {
      "sort": { "value": "asc" }, // this is for sort
      type: "value",
      size: 100
    };
    return acc;
  }, undefined);

  return facets;
}

I added sort but it sort first capital letters than small letter i.e, Azur, Bike, Gixer, Zebra, apple, banana. In this order but i want Azur, apple, banana, Bike, Gixer, Zebra.
Please tell me the solution.

You probably need to change the mapping and transform the text to lowercase.

Have a look at normalizer | Elasticsearch Guide [8.13] | Elastic

in this one they're directly accessing core elasticsearch. but we're accessing through appsearch.

Ok. I moved your question to Elastic Search with the enterprise-app-search tag.

1 Like

Does your use case support case insensitivity? Then as @dadoonet suggested, adjusting your mappings and using a lowercase filter is the easiest way to resolve this.

No, It does not support case insensitivity.
Result i get : Azur, Bike, Gixer, Zebra, apple, banana.
Result i want: Azur, apple, banana, Bike, Gixer, Zebra.

I want it to be case iinsensitivity. Could you please elaborate How to do it?

Thanks

You want to normalize it when you index it, by defining a custom analyzer in your mappings.

Here's an example of how it works:

PUT /lowercase_example/
{
  "settings": {
    "analysis": {
      "normalizer": {
        "lowercase_filter": {
          "type": "custom",
          "filter": [
            "lowercase"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "value": {
        "normalizer": "lowercase_filter",
        "type": "keyword"
      },
      "raw_value": {
        "type": "keyword"
      }
    }
  }
}

So you see here that I have an analyzer that will apply the lowercase filter. I have 2 keyword fields, 1 that uses this analyzer and one that doesn't.

Now let's add a few sample documents:

PUT lowercase_example/_doc/1
{
  "value": "Apple",
  "raw_value": "Apple"
}
PUT lowercase_example/_doc/2
{
  "value": "Banana",
  "raw_value": "Banana"
}
PUT lowercase_example/_doc/3
{
  "value": "avocado",
  "raw_value": "avocado"
}

If you do a terms aggregation on the raw value that doesn't use the lowercase filter, the results are out of the order that you want because they're case insensitive:

GET lowercase_example/_search
{
  "size": 0,
  "aggs": {
    "my_agg": {
      "terms": {
        "field": "raw_value",
        "order": { "_key": "asc" }
      }
    }
  }
}

However if you aggregate on the field you applied the filter it lowercases everything:

GET lowercase_example/_search
{
  "size": 0,
  "aggs": {
    "my_agg": {
      "terms": {
        "field": "value",
        "order": { "_key": "asc" }
      }
    }
  }
}

Thanks for detailed explanation. It is not elasticsearch, but elastic appsearch. There is no option to use case insensitive facet results in appsearch. Could you please help me to resolve this one in appsearch?

You can absolutely use this strategy in App Search using an Elasticsearch index engine.

As you can see in the screenshot, I plugged in the example I gave you and created an engine, and the lowercase normalizer does what you're asking for.

Thanks
I want

  • Apple
  • avacado
  • Banana
    this sequence (all the A's or a's irrespective of capital or small then B's or b's and so on )
    Please suggest?

You can experiment with other mappings to see if you can get what you want, or experiment with other ways to do this on the client side.

1 Like

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