10up / ElasticPress

A fast and flexible search and query engine for WordPress.
https://elasticpress.io
GNU General Public License v2.0
1.25k stars 312 forks source link

Problem with sorting by swedish chars #3819

Closed klingberg closed 7 months ago

klingberg commented 9 months ago

Describe your question

Since I updated to version 5.0.2 my custom posts (in wp api call) are no longer sorted correctly. Å is treated as A, Ä is treated as A and Ö is treated as O. When I use version 4.5.2 swedish chars are sorted correctly.

I tried to fiddle with this solution https://github.com/10up/ElasticPress/issues/977 but I get an error when I try to sync. My guess is that some of the array keys has changed names since this solution was posted so I wonder if you could help me with an updated workaround?

Code of Conduct

felipeelia commented 8 months ago

@klingberg can you please share your ElasticPress Status Report? Thanks

klingberg commented 8 months ago

Hi, sorry for my late reply!

Environment

ElasticPress Version 5.0.2 
PHP Version 7.4.33
WordPress Version 6.4.3

Elastic settings

Elasticsearch Host URL: http://search:9200
Index Prefix    
Elasticsearch Language: sv_SE
Content Items per Index Cycle: 350
Network Active: false

WP Query Args

{
  "author__in": [],
  "author__not_in": [],
  "post__not_in": [],
  "post__in": [],
  "order": "ASC",
  "orderby": "meta_value",
  "paged": 1,
  "s": "",
  "search_columns": [],
  "post_status": [
    "publish"
  ],
  "date_query": [],
  "posts_per_page": 25,
  "tax_query": [
    {
      "taxonomy": "contact_group",
      "field": "term_id",
      "terms": [
        120
      ],
      "include_children": false,
      "operator": "IN"
    }
  ],
  "post_type": "contact",
  "meta_key": "last_name",
  "ignore_sticky_posts": true,
  "error": "",
  "m": "",
  "p": 0,
  "post_parent": "",
  "subpost": "",
  "subpost_id": "",
  "attachment": "",
  "attachment_id": 0,
  "name": "",
  "pagename": "",
  "page_id": 0,
  "second": "",
  "minute": "",
  "hour": "",
  "day": 0,
  "monthnum": 0,
  "year": 0,
  "w": 0,
  "category_name": "",
  "tag": "",
  "cat": "",
  "tag_id": "",
  "author": "",
  "author_name": "",
  "feed": "",
  "tb": "",
  "meta_value": "",
  "preview": "",
  "sentence": "",
  "title": "",
  "fields": "",
  "menu_order": "",
  "embed": "",
  "category__in": [],
  "category__not_in": [],
  "category__and": [],
  "post_name__in": [],
  "tag__in": [],
  "tag__not_in": [],
  "tag__and": [],
  "tag_slug__in": [],
  "tag_slug__and": [],
  "post_parent__in": [],
  "post_parent__not_in": [],
  "lang": "sv",
  "update_post_term_cache": true,
  "ep_integrate": true,
  "suppress_filters": false,
  "cache_results": true,
  "update_menu_item_cache": false,
  "lazy_load_term_meta": true,
  "update_post_meta_cache": true,
  "nopaging": false,
  "comments_per_page": "50",
  "no_found_rows": false,
  "taxonomy": "contact_group",
  "term_id": 120
}

Query Body

{
  "from": 0,
  "size": 25,
  "post_filter": {
    "bool": {
      "must": [
        {
          "bool": {
            "must": [
              {
                "terms": {
                  "terms.contact_group.term_id": [
                    120
                  ]
                }
              },
              {
                "terms": {
                  "terms.language.slug": [
                    "sv"
                  ]
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "exists": {
                  "field": "meta.last_name"
                }
              }
            ]
          }
        },
        {
          "terms": {
            "post_type.raw": [
              "contact"
            ]
          }
        },
        {
          "term": {
            "post_status": "publish"
          }
        },
        {
          "bool": {
            "must_not": [
              {
                "terms": {
                  "meta.ep_exclude_from_search.raw": [
                    "1"
                  ]
                }
              }
            ]
          }
        },
        {
          "term": {
            "terms.language.term_taxonomy_id": 5
          }
        }
      ]
    }
  },
  "query": {
    "match_all": {
      "boost": 1
    }
  },
  "sort": [
    {
      "meta.last_name.value.sortable": {
        "order": "asc"
      }
    }
  ]
}

I now see in the status report that I have an error:

Query Result

{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "No mapping found for [meta.last_name.value.sortable] in order to sort on",
        "index_uuid": "iUP31JfMR-aP-PMJ0THraA",
        "index": "test8770wp-post-1"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "can_match",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "test8770wp-post-1",
        "node": "u119MDJWStKUkERhi5cdZQ",
        "reason": {
          "type": "query_shard_exception",
          "reason": "No mapping found for [meta.last_name.value.sortable] in order to sort on",
          "index_uuid": "iUP31JfMR-aP-PMJ0THraA",
          "index": "test8770wp-post-1"
        }
      }
    ]
  },
  "status": 400
}

This is what causes the error:

add_filter('rest_contact_query', function($args, $request) {
    $args['orderby'] = 'meta_value';
    $args['meta_key'] = 'last_name';

    return $args;
}, 10, 2 );

If I remove the filter above I get no errors and the posts are ordered by post title but still in incorrect order with "å" being treated as "a" etc. I should also mention that I use Polylang to separate Swedish and English results.

felipeelia commented 8 months ago

Hi @klingberg, thanks. Although that helps, I meant the ElasticPress Status Report that you can find by going to your WordPress dashboard, then ElasticPress > Status Report.

For the error you are seeing, did you include last_name as an indexable meta field in your Weighting Dashboard? If not, you'll need to do it, and resync.

klingberg commented 8 months ago

Hi, sorry I just provided the details that I thought were relevant. Here is the complete report:

## Failed Queries ##

## WordPress ##

### WordPress Environment ###
wp_version: 6.4.3
home_url: http://test:8770
site_url: http://test:8770/wp
is_multisite: false
theme: Main theme (1.2.1)
parent_theme: Main theme (1.2.1)
plugins: ACF Content Analysis for Yoast SEO (3.1), Admin Taxonomy Filter (1.0.2), Advanced Custom Fields: Icon (1.0.0), Debug Bar (1.1.4), Duplicate Page (4.5.3), ElasticPress (5.0.2), Gravity Forms (2.8.2), GTM4WP - A Google Tag Manager (GTM) plugin for WordPress (1.20), Polylang Pro (3.5.3), Redirection (5.4.2), and Yoast SEO (21.7)
revisions: 10

### Server Environment ###
php_version: 7.4.33
memory_limit: 124M
timeout: 30

## Indexable Content ##

### Kungl. Vetenskapsakademien — http://test:8770/wp ###
post_count: 1
page_count: 182
award_winner_count: 1,787
contact_count: 1,372
event_count: 405
news_count: 1,279
scholarship_count: 43
post_meta_keys: 0
page_meta_keys: 0
award_winner_meta_keys: 0
contact_meta_keys: 1
event_meta_keys: 0
news_meta_keys: 0
scholarship_meta_keys: 0
total-all-post-types: 1
distinct-meta-keys: last_name

## ElasticPress ##

### Settings ###
host: http://search:9200
index_prefix: 
language: sv_SE
per_page: 350
network_active: false

### Timeouts ###
request_timeout: 5
index_document_timeout: 15
bulk_request_timeout: 30

## Elasticsearch Indices ##

### test8770wp-post-1 ###
health: yellow
status: open
index: test8770wp-post-1
uuid: JH2qzXYNQWCOVJdAVbSyJA
pri: 5
rep: 1
docs.count: 5067
docs.deleted: 0
store.size: 12.9mb
pri.store.size: 12.9mb
total_fields_limit: 5000
analyzer_language: swedish
stop_language: _swedish_
snowball_language: Swedish

## Last Sync ##

### 2024/02/11 11:56:46 am ###
method: WP Dashboard
is_full_sync: Yes
end_date_time: 2024/02/11 11:57:02 am
total_time: 0 hours, 0 minutes, 17 seconds
total: 5067
synced: 5067
skipped: 0
failed: 0
errors: array (
)
trigger: manual
final_status: success

## Feature Settings ##

### Custom Search Results ###
active: true
force_inactive: false

### Filters ###
active: true
force_inactive: false
match_type: all

### Post Search ###
active: true
decaying_enabled: 1
force_inactive: false
highlight_enabled: 0
highlight_excerpt: 0
highlight_tag: mark
synonyms_editor_mode: simple
synonyms: <pre># Defined sets ( equivalent synonyms).
sneakers, tennis shoes, trainers, runners

# Defined alternatives (explicit mappings).
shoes => sneaker, sandal, boots, high heels</pre>
weighting: array (
  'post' => 
  array (
    'post_title' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_content' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_excerpt' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'author_name' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'terms.post_tag.name' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'terms.category.name' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'terms.ep_custom_result.name' => 
    array (
      'enabled' => true,
      'weight' => 9999,
      'fuzziness' => false,
    ),
  ),
  'page' => 
  array (
    'post_title' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_content' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_excerpt' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'author_name' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'terms.ep_custom_result.name' => 
    array (
      'enabled' => true,
      'weight' => 9999,
      'fuzziness' => false,
    ),
  ),
  'award_winner' => 
  array (
    'post_title' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_content' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_excerpt' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'author_name' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'terms.ep_custom_result.name' => 
    array (
      'enabled' => true,
      'weight' => 9999,
      'fuzziness' => false,
    ),
  ),
  'contact' => 
  array (
    'post_title' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_content' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_excerpt' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'author_name' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'terms.ep_custom_result.name' => 
    array (
      'enabled' => true,
      'weight' => 9999,
      'fuzziness' => false,
    ),
    'meta.last_name.value' => 
    array (
      'enabled' => true,
      'weight' => 100,
    ),
  ),
  'event' => 
  array (
    'post_title' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_content' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_excerpt' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'author_name' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'terms.ep_custom_result.name' => 
    array (
      'enabled' => true,
      'weight' => 9999,
      'fuzziness' => false,
    ),
  ),
  'news' => 
  array (
    'post_title' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_content' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_excerpt' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'author_name' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'terms.category.name' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'terms.ep_custom_result.name' => 
    array (
      'enabled' => true,
      'weight' => 9999,
      'fuzziness' => false,
    ),
  ),
  'scholarship' => 
  array (
    'post_title' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_content' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'post_excerpt' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'author_name' => 
    array (
      'enabled' => true,
      'weight' => 1,
    ),
    'terms.ep_custom_result.name' => 
    array (
      'enabled' => true,
      'weight' => 9999,
      'fuzziness' => false,
    ),
  ),
)

### Related Posts ###
active: true
force_inactive: false

Adding the meta field "last_name" in the Weighting Dashboard cleared the error but the posts are still sorted in an incorrect order (åäö still treated as aao).

felipeelia commented 8 months ago

Thanks, @klingberg, that all looks good. I'll need you to do something else now.

Do you mind installing our debugging plugins, performing a search that returns the wrong results, opening the ElasticPress panel in Query Monitor, clicking on "Download Requests Info" and sharing it with us? Thanks

klingberg commented 8 months ago

Hi!

I have the debugging plugin installed but is it possible to get the debugging information when I fetch the data through an ajax api call? Sorry I did not make this very clear in my description.

felipeelia commented 8 months ago

Hi @klingberg, it will not, but you can go to ElasticPress -> Query Log, and enable it to log AJAX requests there. If you do that, run a search, and come back, it should have the queries that went through ElasticPress in an AJAX context.

klingberg commented 7 months ago

Hi!

I think I have found the difference between version 4.5.2 and 5.0.2. The "sort" setting in 5.0.2 seems to sort on a slugified version of the meta field. Here are parts of the query logs:

4.5.2

### http://test:8770/?page=ep-query-log (2024-02-29 10:33:42) ###
es_req: POST http://search:9200/test8770wp-post-1/_search
request_id: 04f8386800704b3c9f627023455d15ee
query_time: 7.2119235992432
wp_args: array (
  'author__in' => 
  array (
  ),
  'author__not_in' => 
  array (
  ),
  'post__not_in' => 
  array (
  ),
  'post__in' => 
  array (
  ),
  'order' => 'ASC',
  'orderby' => 'meta_value',
  'paged' => 104,
  's' => '',
  'search_columns' => 
  array (
  ),
  'post_status' => 
  array (
    0 => 'publish',
  ),
  'date_query' => 
  array (
  ),
  'posts_per_page' => 6,
  'tax_query' => 
  array (
    0 => 
    array (
      'taxonomy' => 'contact_group',
      'field' => 'term_id',
      'terms' => 
      array (
        0 => 120,
      ),
      'include_children' => false,
      'operator' => 'IN',
    ),
  ),
  'post_type' => 'contact',
  'meta_key' => 'last_name',
  'ignore_sticky_posts' => true,
  'error' => '',
  'm' => '',
  'p' => 0,
  'post_parent' => '',
  'subpost' => '',
  'subpost_id' => '',
  'attachment' => '',
  'attachment_id' => 0,
  'name' => '',
  'pagename' => '',
  'page_id' => 0,
  'second' => '',
  'minute' => '',
  'hour' => '',
  'day' => 0,
  'monthnum' => 0,
  'year' => 0,
  'w' => 0,
  'category_name' => '',
  'tag' => '',
  'cat' => '',
  'tag_id' => '',
  'author' => '',
  'author_name' => '',
  'feed' => '',
  'tb' => '',
  'meta_value' => '',
  'preview' => '',
  'sentence' => '',
  'title' => '',
  'fields' => '',
  'menu_order' => '',
  'embed' => '',
  'category__in' => 
  array (
  ),
  'category__not_in' => 
  array (
  ),
  'category__and' => 
  array (
  ),
  'post_name__in' => 
  array (
  ),
  'tag__in' => 
  array (
  ),
  'tag__not_in' => 
  array (
  ),
  'tag__and' => 
  array (
  ),
  'tag_slug__in' => 
  array (
  ),
  'tag_slug__and' => 
  array (
  ),
  'post_parent__in' => 
  array (
  ),
  'post_parent__not_in' => 
  array (
  ),
  'lang' => 'sv',
  'update_post_term_cache' => true,
  'ep_integrate' => true,
  'suppress_filters' => false,
  'cache_results' => true,
  'update_menu_item_cache' => false,
  'lazy_load_term_meta' => true,
  'update_post_meta_cache' => true,
  'nopaging' => false,
  'comments_per_page' => '50',
  'no_found_rows' => false,
  'taxonomy' => 'contact_group',
  'term_id' => 120,
)
status_code: 200
body: {"from":618,"size":6,"post_filter":{"bool":{"must":[{"bool":{"must":[{"terms":{"terms.contact_group.term_id":[120]}},{"terms":{"terms.language.slug":["sv"]}}]}},{"bool":{"must":[{"exists":{"field":"meta.last_name"}}]}},{"terms":{"post_type.raw":["contact"]}},{"term":{"post_status":"publish"}},{"bool":{"must_not":[{"terms":{"meta.ep_exclude_from_search.raw":["1"]}}]}},{"term":{"terms.language.term_taxonomy_id":5}}]}},"query":{"match_all":{"boost":1}},"sort":[{"meta.last_name.raw":{"order":"asc"}}]}
result: array (
  'took' => 3,
  'timed_out' => false,
  '_shards' => 
  array (
    'total' => 5,
    'successful' => 5,
    'skipped' => 0,
    'failed' => 0,
  ),
  'hits' => 
  array (
    'total' => 
    array (
      'value' => 631,
      'relation' => 'eq',
    ),
    'max_score' => NULL,
    'hits' => 
    array (
      0 => 
      array (
        '_index' => 'test8770wp-post-1',
        '_type' => '_doc',
        '_id' => '6627',
        '_score' => NULL,
        '_source' => 
        array (
          'post_id' => 6627,
          'ID' => 6627,
          'post_author' => 
          array (
            'raw' => '',
            'login' => '',
            'display_name' => '',
            'id' => '',
          ),
          'post_date' => '2022-06-08 21:24:54',
          'post_date_gmt' => '2022-06-08 21:24:54',
          'post_title' => 'T Åk',
          'post_excerpt' => '',
          'post_content_filtered' => '',
          'post_content' => '',
          'post_status' => 'publish',
          'post_name' => 't-ak',
          'post_modified' => '2022-06-08 21:24:54',
          'post_modified_gmt' => '2022-06-08 21:24:54',
          'post_parent' => 0,
          'post_type' => 'contact',
          'post_mime_type' => '',
          'permalink' => 'http://test:8770/kontakt/t-ak/',
          'terms' => 
          array (
            'language' => 
            array (
              0 => 
              array (
                'term_id' => 5,
                'slug' => 'sv',
                'name' => 'Svenska',
                'parent' => 0,
                'term_taxonomy_id' => 5,
                'term_order' => 0,
                'facet' => '{"term_id":5,"slug":"sv","name":"Svenska","parent":0,"term_taxonomy_id":5,"term_order":0}',
              ),
            ),
            'contact_group' => 
            array (
              0 => 
              array (
                'term_id' => 120,
                'slug' => 'ledamoter',
                'name' => 'Ledamöter',
                'parent' => 0,
                'term_taxonomy_id' => 120,
                'term_order' => 0,
                'facet' => '{"term_id":120,"slug":"ledamoter","name":"Ledam\\u00f6ter","parent":0,"term_taxonomy_id":120,"term_order":0}',
              ),
            ),
            'contact_title' => 
            array (
              0 => 
              array (
                'term_id' => 1330,
                'slug' => 'klassen-for-fysik',
                'name' => 'Klassen för fysik',
                'parent' => 0,
                'term_taxonomy_id' => 1330,
                'term_order' => 0,
                'facet' => '{"term_id":1330,"slug":"klassen-for-fysik","name":"Klassen f\\u00f6r fysik","parent":0,"term_taxonomy_id":1330,"term_order":0}',
              ),
            ),
          ),
          'meta' => 
          array (
            'last_name' => 
            array (
              0 => 
              array (
                'value' => 'Åk',
                'raw' => 'Åk',
                'boolean' => false,
                'date' => '1970-01-01',
                'datetime' => '1970-01-01 00:00:01',
                'time' => '00:00:01',
              ),
            ),
            'nationality_id' => 
            array (
              0 => 
              array (
                'value' => '1',
                'raw' => '1',
                'long' => 1,
                'double' => 1,
                'boolean' => true,
                'date' => '1970-01-01',
                'datetime' => '1970-01-01 00:00:01',
                'time' => '00:00:01',
              ),
            ),
          ),
          'date_terms' => 
          array (
            'year' => 2022,
            'month' => 6,
            'week' => 23,
            'dayofyear' => 158,
            'day' => 8,
            'dayofweek' => 3,
            'dayofweek_iso' => 3,
            'hour' => 21,
            'minute' => 24,
            'second' => 54,
            'm' => 202206,
          ),
          'comment_count' => 0,
          'comment_status' => 'closed',
          'ping_status' => 'closed',
          'menu_order' => 0,
          'guid' => 'http://test/contact/t-ak/',
          'thumbnail' => NULL,
        ),
        'sort' => 
        array (
          0 => 'Åk',
        ),
      ),
    ),
  ),
)

5.0.2

### http://test:8770/?page=ep-query-log (2024-02-29 10:15:49) ###
es_req: POST http://search:9200/test8770wp-post-1/_search
request_id: a917478a5cbc483d9805c919161d64ab
query_time: 5.328893661499
wp_args: array (
  'author__in' => 
  array (
  ),
  'author__not_in' => 
  array (
  ),
  'post__not_in' => 
  array (
  ),
  'post__in' => 
  array (
  ),
  'order' => 'ASC',
  'orderby' => 'meta_value',
  'paged' => 1,
  's' => '',
  'search_columns' => 
  array (
  ),
  'post_status' => 
  array (
    0 => 'publish',
  ),
  'date_query' => 
  array (
  ),
  'posts_per_page' => 6,
  'tax_query' => 
  array (
    0 => 
    array (
      'taxonomy' => 'contact_group',
      'field' => 'term_id',
      'terms' => 
      array (
        0 => 120,
      ),
      'include_children' => false,
      'operator' => 'IN',
    ),
  ),
  'post_type' => 'contact',
  'meta_key' => 'last_name',
  'ignore_sticky_posts' => true,
  'error' => '',
  'm' => '',
  'p' => 0,
  'post_parent' => '',
  'subpost' => '',
  'subpost_id' => '',
  'attachment' => '',
  'attachment_id' => 0,
  'name' => '',
  'pagename' => '',
  'page_id' => 0,
  'second' => '',
  'minute' => '',
  'hour' => '',
  'day' => 0,
  'monthnum' => 0,
  'year' => 0,
  'w' => 0,
  'category_name' => '',
  'tag' => '',
  'cat' => '',
  'tag_id' => '',
  'author' => '',
  'author_name' => '',
  'feed' => '',
  'tb' => '',
  'meta_value' => '',
  'preview' => '',
  'sentence' => '',
  'title' => '',
  'fields' => '',
  'menu_order' => '',
  'embed' => '',
  'category__in' => 
  array (
  ),
  'category__not_in' => 
  array (
  ),
  'category__and' => 
  array (
  ),
  'post_name__in' => 
  array (
  ),
  'tag__in' => 
  array (
  ),
  'tag__not_in' => 
  array (
  ),
  'tag__and' => 
  array (
  ),
  'tag_slug__in' => 
  array (
  ),
  'tag_slug__and' => 
  array (
  ),
  'post_parent__in' => 
  array (
  ),
  'post_parent__not_in' => 
  array (
  ),
  'lang' => 'sv',
  'update_post_term_cache' => true,
  'ep_integrate' => true,
  'suppress_filters' => false,
  'cache_results' => true,
  'update_menu_item_cache' => false,
  'lazy_load_term_meta' => true,
  'update_post_meta_cache' => true,
  'nopaging' => false,
  'comments_per_page' => '50',
  'no_found_rows' => false,
  'taxonomy' => 'contact_group',
  'term_id' => 120,
)
status_code: 200
body: {"from":0,"size":6,"post_filter":{"bool":{"must":[{"bool":{"must":[{"terms":{"terms.contact_group.term_id":[120]}},{"terms":{"terms.language.slug":["sv"]}}]}},{"bool":{"must":[{"exists":{"field":"meta.last_name"}}]}},{"terms":{"post_type.raw":["contact"]}},{"term":{"post_status":"publish"}},{"bool":{"must_not":[{"terms":{"meta.ep_exclude_from_search.raw":["1"]}}]}},{"term":{"terms.language.term_taxonomy_id":5}}]}},"query":{"match_all":{"boost":1}},"sort":[{"meta.last_name.value.sortable":{"order":"asc"}}]}
result: array (
  'took' => 1,
  'timed_out' => false,
  '_shards' => 
  array (
    'total' => 5,
    'successful' => 5,
    'skipped' => 0,
    'failed' => 0,
  ),
  'hits' => 
  array (
    'total' => 
    array (
      'value' => 631,
      'relation' => 'eq',
    ),
    'max_score' => NULL,
    'hits' => 
    array (
      0 =>
      array (
        '_index' => 'test8770wp-post-1',
        '_type' => '_doc',
        '_id' => '6627',
        '_score' => NULL,
        '_source' => 
        array (
          'post_id' => 6627,
          'ID' => 6627,
          'post_author' => 
          array (
            'raw' => '',
            'login' => '',
            'display_name' => '',
            'id' => '',
          ),
          'post_date' => '2022-06-08 21:24:54',
          'post_date_gmt' => '2022-06-08 21:24:54',
          'post_title' => 'T Åk',
          'post_excerpt' => '',
          'post_content_filtered' => '',
          'post_content' => '',
          'post_status' => 'publish',
          'post_name' => 't-ak',
          'post_modified' => '2022-06-08 21:24:54',
          'post_modified_gmt' => '2022-06-08 21:24:54',
          'post_parent' => 0,
          'post_type' => 'contact',
          'post_mime_type' => '',
          'permalink' => 'http://test:8770/kontakt/t-ak/',
          'terms' => 
          array (
            'language' => 
            array (
              0 => 
              array (
                'term_id' => 5,
                'slug' => 'sv',
                'name' => 'Svenska',
                'parent' => 0,
                'term_taxonomy_id' => 5,
                'term_order' => 0,
                'facet' => '{"term_id":5,"slug":"sv","name":"Svenska","parent":0,"term_taxonomy_id":5,"term_order":0}',
              ),
            ),
            'contact_group' => 
            array (
              0 => 
              array (
                'term_id' => 120,
                'slug' => 'ledamoter',
                'name' => 'Ledamöter',
                'parent' => 0,
                'term_taxonomy_id' => 120,
                'term_order' => 0,
                'facet' => '{"term_id":120,"slug":"ledamoter","name":"Ledam\\u00f6ter","parent":0,"term_taxonomy_id":120,"term_order":0}',
              ),
            ),
            'contact_title' => 
            array (
              0 => 
              array (
                'term_id' => 1330,
                'slug' => 'klassen-for-fysik',
                'name' => 'Klassen för fysik',
                'parent' => 0,
                'term_taxonomy_id' => 1330,
                'term_order' => 0,
                'facet' => '{"term_id":1330,"slug":"klassen-for-fysik","name":"Klassen f\\u00f6r fysik","parent":0,"term_taxonomy_id":1330,"term_order":0}',
              ),
            ),
          ),
          'meta' => 
          array (
            'last_name' => 
            array (
              0 => 
              array (
                'value' => 'Åk',
                'raw' => 'Åk',
                'boolean' => false,
                'date' => '1970-01-01',
                'datetime' => '1970-01-01 00:00:01',
                'time' => '00:00:01',
              ),
            ),
          ),
          'date_terms' => 
          array (
            'year' => 2022,
            'month' => 6,
            'week' => 23,
            'dayofyear' => 158,
            'day' => 8,
            'dayofweek' => 3,
            'dayofweek_iso' => 3,
            'hour' => 21,
            'minute' => 24,
            'second' => 54,
            'm' => 202206,
          ),
          'comment_count' => 0,
          'comment_status' => 'closed',
          'ping_status' => 'closed',
          'menu_order' => 0,
          'guid' => 'http://test/contact/t-ak/',
          'thumbnail' => NULL,
        ),
        'sort' => 
        array (
          0 => 'ak',
        ),
      ),
    ),
  ),
)
felipeelia commented 7 months ago

Hi @klingberg,

Can you add the snippet below to your codebase (more info here on how to do it), run a full sync (checking that "Delete all data..." checkbox?), and let me know if it works?

/**
 * Remove `'asciifolding'` normalizer from ElasticPress.
 *
 * @param array $mapping The post mapping
 * @return array
 */
function ep_custom_remove_asciifolding( $mapping ) {
    $mapping['settings']['analysis']['normalizer']['lowerasciinormalizer']['filter'] = [ 'lowercase' ];
    return $mapping;
}
add_filter( 'ep_post_mapping', 'ep_custom_remove_asciifolding' );

Thanks!

github-actions[bot] commented 7 months ago

This issue has been automatically closed because there has been no response to our request for more information in the past 3 days. With only the information that is currently available, we are unable to take further action on this ticket. Please reach out if you have found or find the answers we need so that we can investigate further. When the information is ready, you can re-open this ticket to share it with us.

klingberg commented 7 months ago

Sorry for the late reply! The last solutions seems to fix the problem. I also had to add the meta field in the "Search Fields & Weighting" panel. Thank you so much and take care!!