November Happy Hour will be moved to Thursday December 5th.

Any way to exclude certain fields from search?

Vote:
 

When having the '.InAllField()' search, how can we exclude certain fields from searching? I always think it's better to have the blacklist approach (Having 'InAllField()'' and then excluding certain fields) than the whitelist approach (Describing which fields to be searched one by one). Because I do not like to define 100s of fields (in the InFields) if I have to only exclude 2 fields.

My implementation is as below,

var result = client.Search<SamplePage>(GetLanguage(LanguageID))
                .For(Query, SearchHelper.QueryStringQueryAction)
                .InFields(x => x.Name, x => x.Content )
                .InAllField()
                // Blah blah
                .GetResult();

Can't we have something similar to below,

var result = client.Search<SamplePage>(GetLanguage(LanguageID))
                .For(Query, SearchHelper.QueryStringQueryAction)
                .InFields(x => x.Name, x => x.Content )
                .InAllField()
                .ExcludeFields(x => x.Field1, x => x.Field2 )// <---Like this 
                // Blah blah   
                .GetResult();
#218464
Mar 13, 2020 10:00
Vote:
 

Yes I believe we have ExcludeField()

#218467
Mar 13, 2020 10:14
Vote:
 

I have tried this, but it did not work (It still searches for SearchHitURL). 

client.Conventions.ForInstancesOf<ISearchContent>()
                          .ExcludeField(page => page.SearchHitUrl);
#218471
Mar 13, 2020 10:52
Vote:
 

Wait, I mixed things up. InFields let you search in those indexed fields. ExcludeField excludes the field  from being indexed. How can you still search by SearchHitUrl if you don't index it?

#218472
Mar 13, 2020 10:57
- Mar 13, 2020 11:43
My bad, I forgot to state that there is another field contain the same value. However, I do not want to remove the field from being index. I need to exclude that field when searching.
Vote:
 

Regardless I think this is a reasonable request. I will fire a bug for FInd team to look into it, but I don't think it will be added anytime soon.

#218473
Mar 13, 2020 11:00
Vote:
 

Thanks. Meanwhile, is there any alternative way I could achieve that? Or else I have to declare every field that needs to be searched (Whitelist approach)?

#218479
Mar 13, 2020 11:45
Vote:
 

InAllField() does not include every field there is.

It adds querying on one specific special purpose field called the _all field. This field is not analzyed for stemming and is also in theory bad for relevance.

"The _all field is a special catch-all field which concatenates the values of all of the other fields into one big string, using space as a delimiter, which is then analyzed and indexed, but not stored. This means that it can be searched, but not retrieved."


We don't really recommend using .InAllField(). 
We recommend specifying those fields you want to query on with .InField().

#230287
Nov 03, 2020 10:40
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.