Skip to content
Wade Womersley

wade.one

wade womersley – york based software engineer

  • Home
  • 2015
  • July
  • 6
  • Cloudant (IBM) Query – Indexing arrays directly using Erlang

Cloudant (IBM) Query – Indexing arrays directly using Erlang

Posted on July 6, 2015 By Wade No Comments on Cloudant (IBM) Query – Indexing arrays directly using Erlang
Programming

Really short post this one on indexing using Cloudant Query to index arrays in your document, e.g. documents that have a field like this:

{
  "ids": [
    "alpha",
    "bravo",
    "charlie"
  ]
}

I was reading the documentation and just could not get it to index these items using anything but the default _all_docs indexer (don’t use this for large databases!) but then I came across the source code for Mango and hidden in the tests and the implementation was the answer I needed.

To create an index, as the documentation states, you just need to POST to /dbname/_index with something like:

{
  "type": "text",
  "index": {
    "default_analyzer": "keyword",
    "fields": [
      {"name": "ids", "type": "string"}
    ]
  }
}

However, if you try this for an array and perform a search (POST to /dbname/_find {“selector”:{“ids”:”alpha”}}) you’ll get no results! So how do you do it? Ridiculously simply, just change ids to ids.[]:

{
  "type": "text",
  "index": {
    "default_analyzer": "keyword",
    "fields": [
      {"name": "ids.[]", "type": "string"}
    ]
  }
}

The query however isn’t just “ids”: “alpha”, it’s a bit more complex, not much, but a bit: {“selector”:{“ids”:{“$elemMatch”:{“$eq”:”alpha”}}}}.

There may be a better way (without writing your own function(doc){index(“”);…}) but for now, this works and uses native Erland as opposed to Javascript.

Share:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit

Related

Comments

comments

Post navigation

❮ Previous Post: The Crystal Maze is Back – and it’s for all of us!
Next Post: Back to the … Theatres ❯

You may also like

Programming
The Node.js Release Schedule Change Is Good for Production Teams
May 4, 2026
Programming
MongoDB vs DocumentDB
March 26, 2023
Programming
What Good Kotlin Code Feels Like After Too Much Java
April 7, 2026
AI
ChatGPT 5.5 and Codex Feel Like a Real Step Up
April 24, 2026

Leave a Reply Cancel reply

You must be logged in to post a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • AI
  • artificial intelligence
  • Ego-centric
  • Events
  • Films
  • Food
  • Gaming
  • Gym
  • Hardware
  • Holidays
  • News
  • PHP
  • Programming
  • Random Stuff
  • Reviews
  • Science
  • SEO
  • Software
  • Software Engineer
  • Support
  • Uncategorized
  • Work

Copyright © 2026 wade.one.

Theme: Oceanly News Dark by ScriptsTown