Hi Team, I’m using Typesense (`multi_search` endpo...
# community-help
m
Hi Team, I’m using Typesense (
multi_search
endpoint) and noticed that the
exclude_fields
parameter does not seem to work as expected. For example, here’s my search payload:
Copy code
{
  "searches": [
    {
      "collection": "qa-products",
      "q": "*",
      "query_by": "pName,pAlias,pBrand,CardType,sName",
      "exclude_fields": "pPrice",
      "facet_by": "CardType,pBrand,sID",
      "page": 1,
      "per_page": 250,
      "sort_by": "AttribRank:asc,pGroup:asc,pGroupItemDate:desc",
      "filter_by": "(sID:=[0cppGlK500aS1000000])&&(pActive:=[true])&&(pVisibility:=[true])&&(SAC_Activated:=[true])&&(pAttribStatus:=[Active])"
    }
  ]
}
Even though I’ve specified
exclude_fields: "pPrice"
, the
pPrice
field still appears in the
hits
response. When I switch to
include_fields
, it works correctly and hides the fields I don’t want. Is this a known issue or limitation with
exclude_fields
(especially in multi-search)? If so, is there a recommended workaround or plan to fix it in future releases?
h
Hey @Marri Shiva Is it possible for you to provide a minimal example for this issue? Maybe try with
Copy code
"collection": "qa-products",
      "q": "*",
      "exclude_fields": "pPrice"
query first?
m
I tried with minimal, but I am still getting
pPrice
in the response
Copy code
{
  "searches": [
    {
      "collection": "qa-products",
      "q": "*",
      "exclude_fields": "pPrice"
    }
  ]
}
h
Okay so could you share the schema of your collection?
Also a sample document with only the
pPrice
field in it.
m
Copy code
sample document
{
  "document": {
    "AttribName": "Holi mela",
    "AttribRank": 39,
    "AttribType": "Tag",
    "CardType": "Holi mela",
    "ItemDisplay": "yes",
    "SAC_Activated": "true",
    "SCID": "16826666263922nDS200000M",
    "ShopCatalogueID": "16826666263922nDS200000M",
    "SlotIDs": null,
    "Src": "16826666263922nDS200000M",
    "iID": "",
    "id": "16826666264642nDS300000M-Holi-mela",
    "invCsq": "",
    "invMsq": "",
    "isMasterCatalogueItem": "false",
    "pActive": "true",
    "pAisleInfo": "",
    "pAlias": "Chair for the camp",
    "pAttribStatus": "Active",
    "pBrand": "",
    "pCDetails": null,
    "pCategory": "Outdoor Recreation",
    "pCost": 0,
    "pDID": "",
    "pDepartment": "Sports and Outdoors",
    "pDeposits": {},
    "pDescription": "<p><span style=\"background-color: rgb(102, 102, 0);\">This is a </span><span style=\"background-color: rgb(153, 51, 255);\">temporary </span>text</p><p><br></p><p>Dvd dvd f<span style=\"color: rgb(240, 102, 102);\">bfbvfvdvf</span></p><p><br></p><p><br></p><p><br></p>",
    "pGroupItemDate": "2024-01-09T14:42:38.717Z",
    "pID": "16826666264642nDS300000M",
    "pIsInventoried": "true",
    "pIsInventoryOOS": "false",
    "pManufacturerName": "None",
    "pManufacturerUPC": "None",
    "pMsr": "7",
    "pName": "Camping Chair",
    "pPrice": 450.99,
    "pRowState": "Published",
    "pSCategory": "Camping",
    "pScRowState": "Published",
    "pStatus": "Available",
    "pStickers": [],
    "pStoreItemID": "None",
    "pSubsc": "true",
    "pSubscOrders": "false",
    "pTImg": "<https://s3.amazonaws.com/lhmasterimages/ItemCatalogue/3b32b351a6fe394fa280742e923723d784ff5a4fb7bcd087b8>",
    "pTags": [],
    "pTax": "zerotax table",
    "pTemplate": null,
    "pUQMflag": "false",
    "pUniqueLHID": "None",
    "pUnit": 1,
    "pVWeight": "false",
    "pVariantCount": 0,
    "pVisibility": "true",
    "published": "true",
    "sID": "00awrdt50bUS1000000",
    "sName": "GrowMore",
    "sSubscription": ""
  },
  "highlight": {},
  "highlights": [],
  "text_match": 100,
  "text_match_info": {
    "best_field_score": "0",
    "best_field_weight": 12,
    "fields_matched": 4,
    "num_tokens_dropped": 1,
    "score": "100",
    "tokens_matched": 0,
    "typo_prefix_score": 255
  }
}
Copy code
{
  "facet": true,
  "index": true,
  "infix": false,
  "locale": "",
  "name": "pPrice",
  "optional": true,
  "sort": true,
  "stem": false,
  "stem_dictionary": "",
  "store": true,
  "type": "float"
}
h
Can you check if indexing only this document and then sending
Copy code
{
  "searches": [
    {
      "collection": "qa-products",
      "q": "*",
      "exclude_fields": "pPrice"
    }
  ]
}
still includes
pPrice
in the response? If yes, please share the steps in this format https://gist.github.com/jasonbosco/7c3432713216c378472f13e72246f46b
Also, what is your Typesense version?
m
I figured out the problem. When I used a scoped search key, I was able to get pPrice in the response even though I sent exclude_fields. With the search-only key, it is working fine
h
When I used a scoped search key, I was able to get pPrice in the response even though I sent exclude_fields
It must be because exclude_fields is already defined in the key.
m
yes
we use a global search that returns items from multiple shops. For some shops, we need to hide certain fields in the search response, but for other shops we want to return those fields. I know about
exclude_fields
/
include_fields
, but those apply globally to the entire query. Is there a way in Typesense to exclude fields conditionally based on a field value (like
shopId
) directly at the search/query level?
h
I would suggest you to create a search key per
shopId
. It would offer better flexibility for your use case.
m
Thanks for the suggestion. Creating a search key per
shopId
makes sense for shop-specific searches. But in our case, we also have a global search feature that returns items from multiple shops in a single query. In that case, we can’t restrict the key to a single
shopId
, since we need results from all shops together. That’s why we were wondering if there’s any way in Typesense to conditionally exclude fields based on
shopId
within the same global search query
.
h
But in our case, we also have a global search feature that returns items from multiple shops in a single query. In that case, we can’t restrict the key to a single shopId, since we need results from all shops together.
You can have per shop search key and still get unified search result using Union feature.
That’s why we were wondering if there’s any way in Typesense to conditionally exclude fields based on shopId within the same global search query.
This is not possible.