artsy / bearden

A simple database of organizations
MIT License
3 stars 8 forks source link

@jonallured: fix graphql organization schema to use top ranked name #migration #317

Closed cavvia closed 7 years ago

cavvia commented 7 years ago

Our representation of Organization objects via the Search API currently returns an unsorted array of names - API clients should only really see the top ranked name as this is the display name they should use when referring to the organization. The clients currently have no need for the alternate names, though we can add them to the schema if need be in future.

Here I index a name field in Elasticsearch as the authoritative (top ranked) name for an Organization, and additionally index other names in an alternate_names array as is our convention in other search indices. I've adjusted the search query to search on all the names, but now the API only returns the name attribute.

Migration

We need to recreate the index as we are scrapping the names field and adding the name and alternate_names fields in its pace. ES doesn't support deleting existing fields in a live index so in a console we drop the old index and re-declare the mappings for the new one:

Organization.reload_index!

And then we can dispatch our indexing sidekiq workers to populate the new index:

bundle exec rake elasticsearch:reindex
jonallured commented 7 years ago

This looks good to me - merging now and then I'll get it deployed and migrated out to production after I do a bundle update PR. 👍