Searching fields for specific values


(Susie Richard) #1

I'm trying to search the fields of our indices for a specific value. The field I'm checking is 'topic', and I want to find indices that have a value that matches a search string. So, for example, how can I construct a curl command to search to find a 'topic' field that contains the value 'Hello World'? Also, how could I do something similar with a short phrase, searching all of the message fields within an index?

I've tried numerous things from your API docs, and no luck, so any assistance would be appreciated!

Thanks in advance!


(Nik Everett) #2
curl -XPOST localhost:9200/index/_search -d'{
  "query": {
    "match": {
      "topic": "hello world"
    }
  }
}'

That searches in a topic field in the index named index that contains the words hello and world in any order with any proximity to one another. You could also do this:

curl -XPOST localhost:9200/index/_search -d'{
  "query": {
    "match_phrase": {
      "topic": "hello world"
    }
  }
}'

That searches in a topic field in the index named index that contains the words hello and world in that order without any words between them.

Here are some important docs to read:
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html


(system) #3