3

I was using Sharepoint Rest api and the query looked like the one below

http://sitename/HR/_api/web/lists/GetByTitle('Employee')/Items?$top=4000&$filter=( substringof('100',Title) and substringof('ARISPL',Company) and substringof('HIBIS',House_x0020_Name))

Now I want to migrate to Search Api as querying against Note fields is not possible in Rest API

I was able to get items from the list with below query

http://sitename/HR/_api/search/query?querytext='Path:http://sitename/HR/Lists/Employee'

but I am not sure how to add filters against fields with Contains and a and condition

I tried the below query but it didnt work

http://sitename/HR/_api/search/query?querytext='Path:http://sitename/HR/Lists/Employee'&refinementfilters='AND((Department:mvrla)(Title:1000))'

Can someone help?

I want to convert the above rest api query to search api query

3
  • Possibly duplicate sharepoint.stackexchange.com/questions/210151/…, But still i did not get any answer for this Commented Mar 22, 2017 at 7:54
  • Thanks @AbhishekKumarSeth but it doesn't have the question of using contains in Search API Commented Mar 22, 2017 at 7:56
  • 1
    Yes @vignesh, i am agree with you, actually i am also looking for answer something like that, i have tried with Content search webpart also, but no luck. Commented Mar 22, 2017 at 7:58

3 Answers 3

3

You should try out the SharePoint 2013 Search Query Tool. It will help you craft your query and show you the results.

You can use the colon as a contains operator :. In KQL AND is the default behavior between terms. I think your query would be something like: querytext='Path:http://sitename/HR/Lists/Employee/* Department:mvrla Title:1000' which should be the same as: querytext='Path:http://sitename/HR/Lists/Employee/* AND Department:mvrla AND Title:1000'

1
  • 1
    I interpreted 'contains' as a search where : *meth* returns something Commented Mar 25, 2017 at 12:31
2

There is no contains filter

Search has different syntax

8
  • 1
    Danny, I think he's asking for contains in REST Search not the REST OData. Commented Mar 25, 2017 at 12:25
  • Yes, link 3 and 4 point to Search Documentation, are they not correct? Commented Mar 25, 2017 at 12:28
  • The links are great. It was your statement that there is "no contains filter". Do you mean in REST? Commented Mar 26, 2017 at 12:12
  • afaik, not in Search either, you can only have one wildcard in a searchstring(?) So you can't search for *msterda* Commented Mar 27, 2017 at 11:59
  • 3
    Nope, = is equals : is contains. itunity.com/article/… Commented Mar 28, 2017 at 11:23
1

The KQL query to use AND operation is as follows

<<siteurl>>/_api/search/query?querytext='Path:Path:http://sitename/HR/Lists/Employee (Department:mrvla) (Title:1000)'

You should enclose in double quote if you want exact match and space will treat as AND operation.

The above code blocks works as Path starts with given value and Department starts with mrvla and Title starts with 1000. There is no contains operation in a word.

Here is a MSDN article to know the keyword search options.

https://msdn.microsoft.com/en-us/library/office/ee558911.aspx

Thanks, Venkat Konjeti

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.