DEV Community

Discussion on: How to write your own search engine using Node.js and Elastic

Collapse
 
keaglin profile image
Kevon Eaglin • Edited

So I followed this tonight and I like that it's a really concise start with Elastic. I find the docs to be not as explicit as I'd like regarding what I should be doing and when and where and in what context. So thanks for sharing!

There were a couple issues I ran into though. It wasn't immediately clear (to me, someone who doesn't use curl everyday) that we're deleting the index when we go to insert the mapping. I did end up figuring out that I can't just assign a mapping to my index at any old time. I have to create an index at the same time as its mapping.

The next issue I had was with the body of the mapping. I kept getting an error that "properties" wasn't a valid key (and later that my index already existed). I had to make "properties" a child of "mappings" like this:

{ 
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "standard",
        "boost": 2
      },
      "body": {
        "type": "text",
        "analyzer": "english"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

and then I was able to submit that PUT request (which created my index and assigned it this mapping).

When I ran the JS for adding and querying data on the command line, I had (I think) my last issue. Node was complaining that it couldn't find the 'request' module and I was extremely confused. Ended up heading to the npm page for 'request-promise-native'. Turns out... You have to install the 'request' package along with 'request-promise-native'. That could've been clearer in the text.

Anyway. Thanks again. I did end up getting it up and running and I'll definitely be exploring it further!