Search All fields in an Index

Hey There !

I want to do a search where i can access all the documents within the given index to find the word i'm looking for. I see that "_all" has been taken off which brings it down to use only the wildcard search with match_all option or another option is to use wildcard with query_string - is there a good way you can suggest how i can search ?

I'm developing a small project for myself in typescript.
Here's a sample to visualize my question :
Index Name :
Cars

The CARS index has the following columns :
Car Name, Car Brand, Car Type, Car make year, Car manufacture country

Sample :
Civic EX, Honda, Sedan, 2015, USA
Tundra, Toyota, Truck, 2012, USA
Focus, Ford, Sedan, 2018, USA
Mustang, Ford, Sedan, 2019, USA

Now, if i search for the word "or" i need to get any entry having "or" in any of the fields. So, in this search i should get the last 2 entries as they have the texts "or" in one of the field ("or" is available in FORD)

I have used the below but i feel it's a bad way to do it as i'm mentioning every field header here. The reason i use an asterisk (*) is to do a "like" search and not an exact search. So, basically any text having the text "or" anywhere in the word.

I have a feeling even the below is not correct, please help !

body: {
            query: {
query_string:  {
                    query : '*' + searchTxt,
                    fields : [car_name, car_brand, car_type, car_year, car_country]
                   }
         }
},

There are a few things you could do here. First of all you could create your own _all-like field by using copy_to. In your mapping you could copy the values of car_name, car_brand, etc to a new field called something like car_combined for example. Then, you would only have to query that car_combined field.

On that combined field car_combined you could define a custom analyzer that uses ngrams. Using NGrams, you will break up your strings into substrings when indexing. That will allow you to search for or for example, and find Ford, without having to use wildcards.

1 Like

Thank you so much @abdon !

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.