title: Sequelize.js. How to find object in JSON datatype with iLike condition?
body: <p>I have a table named <code>orders</code> having several fields, one of the field is having <code>jsonb</code> datatype. The name of this field is <code>customer_detail</code>. I am storing json object in this field. Now I want to perform search operation on this field, I want to search in orders table with customer name and email.</p>
  <p><strong>Model:</strong></p>
  <pre><code>const Order = db.sequelize.define(
    'orders',
    {
       
      customer_detail: {
        type: db.Sequelize.JSONB
      },
       
    },
    {
      underscored: true,
      paranoid: true
    }
  );
  
  module.exports = Order;
  </code></pre>
  <p><strong>Query:</strong></p>
  <pre><code>const orderData = await model.Order.findAndCountAll({
      where: {
          customer_detail: {
              [Op.contains]: {
                  name: 'search_term',
                  email: 'search_term'
              }
          }
      },
      order: [['id', 'DESC']],
      limit: 50
  });
  </code></pre>
  <p>Above query returns correct result but it matches whole word. So for example if the name of customer is John Doe and I search with only John then it does not return the result but if I search with John Doe then I get correct result.</p>
  <p>I also tried below query but it failed.</p>
  <pre><code>const orderData = await model.Order.findAndCountAll({
      where: {
          customer_detail: {
              [Op.contains]: {
                  name: {
                      [Op.iLike]: '%search_term%'
                  }
                  email:  {
                      [Op.iLike]: '%search_term%'
                  }
              }
          }
      },
      order: [['id', 'DESC']],
      limit: 50
  });
  
    
    
  </code></pre>