简体   繁体   中英

Elastic search multi word partial match using regex with node js

I want to search multi-word using elastic search and node.js. I am using regex for that, but seems like regex works only for a single word. can anyone please help me with that. When I am trying to search for a movie "Sholay" with the input "shol", then I am getting the expected result. But when I am trying to search "3 Idiots" movie with input as "3 idi" it is giving me the empty result. And I checked in my elastic search DB that the movie "3 Idiots" exists.

Please help me with that.

code I am using:

regexp: {
         name: {
                value: query + "*",
                }
         }

I don't understand why you wanted to use regex, if you can only use line.includes(). However, below my solution using regex...

 let keyWords = ["shol", "3 idi"]; let text = `Sholay 3 Idiots abcdef`; keyWords.forEach((x) => { // If the name of the movie has metacharacteres, you will need to scape... console.log(text.match(new RegExp(`^.*${x}.*$`, "gim"))); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM