Using the Search REST API to get all users where their last name begins with a certain letter to make a custom user directory. For example, I hoped that the following would return all users that have a last name that starts with A:


However, that A* is really looking for words that start with A, not last names that start with A, so the above will return users with hyphenated last names where the second part starts with A. So the above will return "Carter-Adams" as part of the result set, which is not what I want.

How do I search to get values where the entire value starts with a certain string, rather than where any word in the value starts with that string?

2 Answers 2


If you are looking to grab the first letter of each last name you could use startsWith in your $filter of the query.


  • 1
    The following did not work: &$filter=startswith(lastname,'K'). This is using the REST Search api which seems to have different options than the other SP Rest services, so I'm using the querytext to specify the query.
    – Mike2500
    Apr 16, 2015 at 17:28

Try using lastname= instead of lastname:

Typically in the Search API a : means "Contains" and an = means "Equals" which will anchor the query to the beginning of the line. I'm not 100% certain it works in this specific case but give it a try and let me know.


For reference, here's the KQL guide.

Depending on the architecture of your application you could always filter the results yourself, just holding them in a list until you prune the ones containing a hyphen.

  • lastname=A* yields no results. (perhaps it's like SQL and = means that the * is not a wildcard)
    – Mike2500
    Apr 16, 2015 at 15:46
  • According to the guide I just linked you can combine the two, they just don't recommend it for exact matching (for obvious reasons). The only other thing I can think of would be adding another parameter for something like lastname<>- to exclude hyphens, but that's just a guess.
    – thanby
    Apr 17, 2015 at 11:42
  • Or put the A* in quotes to make sure it's not combining the wildcard with the next operation.
    – thanby
    Apr 17, 2015 at 11:44

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.