I have a set of users with field_first_name and field_last_name, and i want to create a user search using the search api, to search for users using those fields, but it doesn't seems to be working.

Here is my code:

$query = Index::load('default_index')
          'offset' => 0,
          'limit'  => 12,
      ->addCondition('search_api_datasource', 'entity:user')

It's not fetching any of my users per name. I am missing something?

1 Answer 1


On the first hand, can you check if your content is being indexed properly ? If yes, then I would recommend using the default search box provided by drupal, and see if you get results.

Assuming you are using search api solr module.

  • I eventually found out the issue: i had to add the fields to my index and associate a view mode to the rendered user in: admin > config > search > search-api > index > default_index > fields. It was just a settings issue, my code was ok. I wasn't using Solr, but the Database Server. Jul 26, 2017 at 16:13
  • Cool, good to hear that. Jul 27, 2017 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.