admin管理员组

文章数量:1415491

I have some data indexed in an aws open search instance, which i understand is basically elastic search . the sample data below .

I verified i can do a search via sample search query below. How do i search for items , say that falls in category electronics .

GET _search
{
   "query" : {
      "match_all" : {}
   }
}

sample data

{
  "_index"  :  "my_index",
  "_id"     :  "123abc", 
  "_score"  :  1,
  "_source" :  {
                  "_id"      : "123abc",
                  "vector"   : [ 1, 2, 3 ....],
                  "category" : ["electronics", "stationary" ]
  }
}

I have some data indexed in an aws open search instance, which i understand is basically elastic search . the sample data below .

I verified i can do a search via sample search query below. How do i search for items , say that falls in category electronics .

GET _search
{
   "query" : {
      "match_all" : {}
   }
}

sample data

{
  "_index"  :  "my_index",
  "_id"     :  "123abc", 
  "_score"  :  1,
  "_source" :  {
                  "_id"      : "123abc",
                  "vector"   : [ 1, 2, 3 ....],
                  "category" : ["electronics", "stationary" ]
  }
}
Share Improve this question asked Feb 21 at 2:13 no_reservationsno_reservations 213 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
GET /my_index/_search
{
  "query": {
    "term": {
      "category": "electronics"
    }
  }
}

If you want to set an or condition, you can use the should syntax. If any of the conditions in the should are met, the match will succeed.

GET /my_index/_search
{
  "query": {
    "bool": {
      "should": [
        { "term": { "category": "electronics" } },
        { "term": { "category": "stationary" } }
      ],
      "minimum_should_match": 1
    }
  }
}

本文标签: elasticsearchhow to query based on particular field in elasticopen searchStack Overflow