Search code examples
azure-cognitive-search

Id (key) takes part in BM25 relevance scoring?


In Azure cognitive search if I make 'id' field as key and set to Searchable then is it take part in scoring?

For example:

doc1:- id:'azure123' name:'azure' .. ..

doc2:- id:'gcp123' name: 'azure' .. ..

query:

"search": "azure",
"queryType": "full",
"searchMode": "all",
"searchFields": "name"

It will find 2 docs - but search score can differ (as 'id' key contains search term) ?


Solution

  • Since you explicitly scoped the search request to the "name" field, the content of the ID field should not affect the score. The difference you are seeing in scores may be due to each document ending up in different shard of the index and being subject to different index statistics:

    https://learn.microsoft.com/en-us/azure/search/index-similarity-and-scoring#scoring-statistics-and-sticky-sessions

    You can try using the "scoringStatistics": "global" query parameters to allow using global index statistics rather than local "shard-specific" statistics when computing the score.

    Also, just for your information, in your specific example, the search term "azure" would likely not match an id with the value "azure123" since those would likely results in different tokens (except if you are using very specific custom analyzers, which I doubt you would do on an ID field).