0
votes

I have just implemented ELASTIC SEARCH on my database and I am very new to this. I have to write query that has to-

  1. Search database field "name" with the search text entered by user.

  2. User can also apply filters on search text like country array or colour array or any tags array

  3. It must check if any filter is applied then only it should match it with respective fields in database.

query in mongo be like:

aggregate.match({ '$text': { '$search': searchString } });
if(portarray){
aggregate.match({ 'Port' : { $in:portArray } });
}
if(countriesArray){
 aggregate.match({ 'country' : { $in: countriesArray } });
}

Please help me with this.

1
What do you mean by "I have just implemented ELASTIC SEARCH on my database"? Did you index some data (document(s)) into elasticsearch? If yes, what is the document structure?theDima
Yes, I have completed indexing on all the documents. Collection is mycoll and my indexing is as follows: "country" : { "type" : "string" }, "Port" : { "type" : "string" }, "Name" : { "type" : "string" }komal

1 Answers

0
votes

I'd suggest you read in the official Elasticsearch tutorial, for example: this artice

Fo example, answering your first question, you should query:

GET /yourIndexName/_search
 {
   "query": 
      { "match": 
         { "Name": "Pablo Escobar" } 
      }
 }