最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

elasticsearch - how to query based on particular field in elasticopen search? - Stack Overflow

programmeradmin1浏览0评论

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
    }
  }
}
发布评论

评论列表(0)

  1. 暂无评论