Skip to main content

Usage

Usage

  • Attribute names are case-sensitive.
  • This parameter only works if searchableAttributes isn’t empty or null.
This setting doesn’t support:
  • Target attributes from a comma-separated list of attributes within searchableAttributes. For example, if your searchableAttributes is set to ['title, category', 'content'], you can restrict searches to "content", but not to "title" or "category" individually, or to "title,category".
  • Change the ranking priority of matched attributes. For example, if searchableAttributes is ["title", "category", "content"] and you restrict the search to ["category", "title"], matches in the title attribute still rank higher than matches in category.
  • Apply or override searchableAttributes modifiers such as unordered. This parameter only accepts attribute names. For example, if you configured unordered(title) in searchableAttributes, restrict the search with ["title"], not ["unordered(title)"].

Example

The following example restricts the search to the title and author attributes, even if your searchableAttributes setting includes more.

Current API clients

var response = await client.SearchSingleIndexAsync<Hit>(
  "INDEX_NAME",
  new SearchParams(
    new SearchParamsObject
    {
      Query = "query",
      RestrictSearchableAttributes = new List<string> { "title", "author" },
    }
  )
);
final response = await client.searchSingleIndex(
  indexName: "INDEX_NAME",
  searchParams: SearchParamsObject(
    query: "query",
    restrictSearchableAttributes: [
      "title",
      "author",
    ],
  ),
);
response, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest(
  "INDEX_NAME").WithSearchParams(search.SearchParamsObjectAsSearchParams(
  search.NewEmptySearchParamsObject().SetQuery("query").SetRestrictSearchableAttributes(
    []string{"title", "author"}))))
if err != nil {
  // handle the eventual error
  panic(err)
}
SearchResponse response = client.searchSingleIndex(
  "INDEX_NAME",
  new SearchParamsObject().setQuery("query").setRestrictSearchableAttributes(Arrays.asList("title", "author")),
  Hit.class
);
const response = await client.searchSingleIndex({
  indexName: 'indexName',
  searchParams: { query: 'query', restrictSearchableAttributes: ['title', 'author'] },
});
var response =
  client.searchSingleIndex(
    indexName = "INDEX_NAME",
    searchParams =
      SearchParamsObject(
        query = "query",
        restrictSearchableAttributes = listOf("title", "author"),
      ),
  )
$response = $client->searchSingleIndex(
    'INDEX_NAME',
    ['query' => 'query',
        'restrictSearchableAttributes' => [
            'title',

            'author',
        ],
    ],
);
response = client.search_single_index(
    index_name="INDEX_NAME",
    search_params={
        "query": "query",
        "restrictSearchableAttributes": [
            "title",
            "author",
        ],
    },
)
response = client.search_single_index(
  "INDEX_NAME",
  Algolia::Search::SearchParamsObject.new(query: "query", restrict_searchable_attributes: ["title", "author"])
)
val response = Await.result(
  client.searchSingleIndex(
    indexName = "INDEX_NAME",
    searchParams = Some(
      SearchParamsObject(
        query = Some("query"),
        restrictSearchableAttributes = Some(Seq("title", "author"))
      )
    )
  ),
  Duration(100, "sec")
)
let response: SearchResponse<Hit> = try await client.searchSingleIndex(
    indexName: "INDEX_NAME",
    searchParams: SearchSearchParams.searchSearchParamsObject(SearchSearchParamsObject(
        query: "query",
        restrictSearchableAttributes: ["title", "author"]
    ))
)
index.Search(new Query("query")
{
    RestrictSearchableAttributes = new List{ "title", "author" }
});
res, err := index.Search(
	"query",
	opt.RestrictSearchableAttributes(
		"title",
		"author",
	),
)
index.search(
  new Query("query").setRestrictSearchableAttributes(Arrays.asList(
    "title",
    "author"
  ))
);
index
  .search("query", {
    restrictSearchableAttributes: ["title", "author"],
  })
  .then(({ hits }) => {
    console.log(hits);
  });
val query = query("query") {
    restrictSearchableAttributes {
        +"title"
        +"author"
    }
}

index.search(query)
$results = $index->search('query', [
  'restrictSearchableAttributes' => [
    'title',
    'author'
  ]
]);
results = index.search("query", {"restrictSearchableAttributes": ["title", "author"]})
results = index.search(
  "query",
  {
    restrictSearchableAttributes: [
      "title",
      "author"
    ]
  }
)
client.execute {
  search into "myIndex" query Query(
    query = Some("query"),
    restrictSearchableAttributes = Some(Seq(
      "title",
      "author"
    ))
  )
}
let query = Query("query")
  .set(\.restrictSearchableAttributes, to: [
    "title",
    "author"
  ])

index.search(query: query) { result in
  if case .success(let response) = result {
    print("Response: \(response)")
  }
}
Last modified on May 19, 2026