1

I'm using Meteor (so Javascript, Node, NPM, etc) and would like to provide a simple text input for users to search via Elasticsearch. I would like to be able to use modifiers on the text like + and "" and search for a specific field. I'm looking for something that can convert a plain text input into Elasticsearch Query DSL.

These would be some example queries:

This query would mean that the keyword "tatooine" must exist:

stormtrooper +tatooine

This would mean that "death star" should be one keyword:

stormtrooper "death star"

This would search for the keyword "bloopers" only in the category field:

stormtrooper category=bloopers

Is there a library that can do this? Can a generic solution exist or is this why I can't find any existing answers to this?

1 Answer 1

1

simple_query_string would support your query syntax out of the box, except for category=bloopers which should be category:bloopers instead, but otherwise it should work:

curl -XPOST localhost:9200/your_index/_search -d '{
  "query": {
    "simple_query_string": {
      "query": "stormtrooper category:bloopers"
    }
  }
}'

curl -XPOST localhost:9200/your_index/_search -d '{
  "query": {
    "simple_query_string": {
      "query": "stormtrooper +tatooine"
    }
  }
}'

You can also send the query in the query string directly like this:

curl -XPOST localhost:9200/your_index/_search?q=stormtrooper%20%22death%20star%22"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.