The Swiftype Blog / New Feature: Location Attributes Can Now Have Multiple Values

New Feature: Location Attributes Can Now Have Multiple Values

We’ve made a small change in how location attributes are handled within Swiftype. Now you can have multiple values for location attributes associated with one document. This is great news for many of our customers, because now, if you have a page listing all your store locations, that page can now be associated with all of those locations. Previously, to make sure searchers would be able to find all your locations, you’d need a unique page for each location.

Here’s how to do it using Meta Tags:

  <title>page title | website name</title>
  <meta class="swiftype" name="title" data-type="string" content="page title" />
  <meta class="swiftype" name="body" data-type="text" content="this is the body content" />
  <meta class="swiftype" name="url" data-type="enum" content="" />
  <meta class="swiftype" name="store_location" data-type="location" content="25,-10" />
  <meta class="swiftype" name="store_location" data-type="location" content="20,-15" />
  <meta class="swiftype" name="store_location" data-type="location" content="40,-10" />
  <meta class="swiftype" name="store_location" data-type="location" content="20,-20" />
  <meta class="swiftype" name="tags" data-type="string" content="tag1" />
  <meta class="swiftype" name="tags" data-type="string" content="tag2" />

As you can see, there are 4 store_location fields. You can also add the attributes to existing elements if you’d prefer. You can find out more in our Meta Tags 2 documentation.

You can also use repeated location fields with the Swiftype API. For example, to create a Document with multiple locations similar to the Meta Tags example above:

Swiftype.api_key = 'your_api_key'
client =
client.create_document('your_engine', 'your_document_type', {
  :external_id => 'unique_id',
  :fields => [
    {:name => 'title', :type => 'string', :value => 'document title'},
    {:name => 'store_location', :type => 'location', :value => {:lat => 25, :lon => -10}},
    {:name => 'store_location', :type => 'location', :value => {:lat => 20, :lon => -15}},
    {:name => 'store_location', :type => 'location', :value => {:lat => 40, :lon => -10}},
    {:name => 'store_location', :type => 'location', :value => {:lat => 25, :lon => -20}},

We’re looking forward to this feature helping out a lot of our customers, so please, reach out with any questions or comments.

Subscribe to our blog