Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Search exact words in elastichsearch

Using elasticseach, I want to search all documents with two words.

I use:

{ "query": { "match": { "text": "word1 word2" } } }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

but instead of having documents with word1 and word2, i have documents with word1 or word2.
¿how can i search docs with word1 AND word2?

>Solution :

You can use operator in the query.

The operator parameter can be set to or or and to control the boolean
clauses (defaults to or).

POST test_index/_doc
{"text":"word1"}
POST test_index/_doc
{"text":"word2"}
POST test_index/_doc
{"text":"word1 word2"}


GET test_index/_search
{
  "query": {
    "match": {
      "text": {
        "query": "word1 word2",
        "operator": "and"
      }
    }
  }
}

Reference: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#query-dsl-match-query-boolean

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading