Chris Snow
Chris Snow

Reputation: 24588

how can I index more than one field to allow querying them all without providing the field name?

I would like to search all fields in my document without having to specify the field name when using a Cloudant Search index.

The cloudant docs provide an example of a default field indexing on the doc._id:

function(doc){
  index("default", doc._id);
  if (doc.min_length){
    index("min_length", doc.min_length, {"store": true});
  }
  if (doc.diet){
    index("diet", doc.diet, {"store": true});
  }
  if (doc.latin_name){
    index("latin_name", doc.latin_name, {"store": true});
  }
  if (doc.class){
    index("class", doc.class, {"store": true});
  }
}

The docs also provide this description:

If the special value "default" is used when defining the name, you do not have to specify a field name at query time.

Can I define more that one "default" index? E.g.

function(doc){
  index("default", doc._id);
  index("default", doc.min_length, {"store": true});
  ... 
}

Upvotes: 0

Views: 72

Answers (1)

Mayya Sharipova
Mayya Sharipova

Reputation: 405

Yes, you can define as many "default" indexes at you like. It seems that even mixing types should be fine for queries.

Upvotes: 1

Related Questions