Skip to content

Commit edd10ef

Browse files
authored
Merge pull request #43907 from allantargino/patch-2
Adding filters and selectors
2 parents bfda34f + 6bc15fa commit edd10ef

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

articles/search/search-more-like-this.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,50 @@ ms.date: 11/04/2019
2222

2323
By default, the contents of all top-level searchable fields are considered. If you want to specify particular fields instead, you can use the `searchFields` parameter.
2424

25-
You cannot use moreLikeThis on searchable sub-fields in a [complex type](search-howto-complex-data-types.md).
25+
You cannot use `MoreLikeThis` on searchable sub-fields in a [complex type](search-howto-complex-data-types.md).
2626

27-
## Examples
27+
## Examples
2828

29-
Below is an example of a moreLikeThis query. The query finds documents whose description fields are most similar to the field of the source document as specified by the `moreLikeThis` parameter.
29+
All following examples use the hotels sample from [Quickstart: Create a search index in the Azure portal](search-get-started-portal.md).
30+
31+
### Simple query
32+
33+
The following query finds documents whose description fields are most similar to the field of the source document as specified by the `moreLikeThis` parameter:
3034

3135
```
32-
Get /indexes/hotels/docs?moreLikeThis=1002&searchFields=description&api-version=2019-05-06-Preview
36+
GET /indexes/hotels-sample-index/docs?moreLikeThis=29&searchFields=Description&api-version=2019-05-06-Preview
3337
```
3438

39+
In this example, the request searches for hotels similar to the one with `HotelId` 29.
40+
Rather than using HTTP GET, you can also invoke `MoreLikeThis` using HTTP POST:
41+
3542
```
36-
POST /indexes/hotels/docs/search?api-version=2019-05-06-Preview
43+
POST /indexes/hotels-sample-index/docs/search?api-version=2019-05-06-Preview
3744
{
38-
"moreLikeThis": "1002",
39-
"searchFields": "description"
45+
"moreLikeThis": "29",
46+
"searchFields": "Description"
4047
}
4148
```
4249

50+
### Apply filters
51+
52+
`MoreLikeThis` can be combined with other common query parameters like `$filter`. For instance, the query can be restricted to only hotels whose category is 'Budget' and where the rating is higher than 3.5:
53+
54+
```
55+
GET /indexes/hotels-sample-index/docs?moreLikeThis=20&searchFields=Description&$filter=(Category eq 'Budget' and Rating gt 3.5)&api-version=2019-05-06-Preview
56+
```
57+
58+
### Select fields and limit results
59+
60+
The `$top` selector can be used to limit how many results should be returned in a `MoreLikeThis` query. Also, fields can be selected with `$select`. Here the top three hotels are selected along with their ID, Name, and Rating:
61+
62+
```
63+
GET /indexes/hotels-sample-index/docs?moreLikeThis=20&searchFields=Description&$filter=(Category eq 'Budget' and Rating gt 3.5)&$top=3&$select=HotelId,HotelName,Rating&api-version=2019-05-06-Preview
64+
```
4365

4466
## Next steps
4567

4668
You can use any web testing tool to experiment with this feature. We recommend using Postman for this exercise.
4769

4870
> [!div class="nextstepaction"]
49-
> [Explore Azure Cognitive Search REST APIs using Postman](search-get-started-postman.md)
71+
> [Explore Azure Cognitive Search REST APIs using Postman](search-get-started-postman.md)

0 commit comments

Comments
 (0)