1

I want to be able to match a substring using a JSON index, but I can't seem to work out how to do it.

I have a record in the data with a data.name property of A SIGN DESIGN PTY. LTD.. My index is defined as follows:

db.index({
  name: 'subbies_text',
  type: 'json',
  index: {
    fields: ['data.name']
  },
})

Is there a selector that I can use that will perform a substring match so that I can search for "sign" or "sign design" and have "A SIGN DESIGN PTY. LTD." included in the search results?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
simon
  • 933
  • 1
  • 9
  • 17

1 Answers1

1

You can achieve that with "$regex". Suppose you have succeeded created a json index named "subbies_text", next is the example of the query:

{"selector": { "_id": { "$gt": 0 }, "subbies_text":{"$regex":"SIGN" } }, "fields": [ "_id", "_rev", "name" ]}
Susan
  • 11
  • 1
  • Thanks. Is it possible to manipulate the indexed values with this approach? How can I uppercase values to provide case insensitivity? How can I remove spaces from formatted numbers so they match any formatting in the query string? It feels to me that querying a design doc directly is a better solution. – simon Aug 16 '16 at 05:43