Skip to content

how to set a GSI for condition ? #622

Description

@pribadi1st

Hi, i want to ask a simple question
how to set a GSI for a condition such as contains

i have a table called messages.rb

but when i do a query

Message.where('text_html.contains': "some text")

the console give me a warning

Queries without an index are forced to use scan and are generally much slower than indexed queries!
You can index this query by adding index declaration to messages.rb:
* global_secondary_index hash_key: 'some-name', range_key: 'some-another-name'
* local_secondary_index range_key: 'some-name'
Not indexed attributes: :text_html.contains

this is my messages.rb and how i define the attribute

class Message
  include Dynamoid::Document

  table name: :messages, key: :id, capacity_mode: :on_demand

  field :message, :string
  # global_secondary_index hash_key: 'some-name'
  field :creator_id, :string
  field :deleted_at, :datetime

  global_secondary_index name: 'message_index', hash_key: :message, projected_attributes: :all, range_key: :created_at,
                         capacity_mode: :on_demand
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions