0

Hi i'm elasticsearch newbie and i have troubles with a query. I have data's as

{
    "user_id": "1",
    "date": "141462121",
    "name": "John",
    "surname": "Doe"
    "activity": [
      {
        "type": [
          "Outdoor",
          "Extreme"
        ],
        "name": "Example",
        "price": {
          "value": 50,
          "currency": "USD"
        }
      }
    ]
    "searchs": ""
  }
},
{
    "user_id": "2",
    "date": "141462121",
    "name": "Jane",
    "surname": "Doe"
    "activity": [
      {
        "type": [
          "Indoor"
        ],
        "name": "Example2",
        "price": {
          "value": 100,
          "currency": "USD"
        }
      },
      {
        "type": [
          "Outdoor"
        ],
        "name": "Example3",
        "price": {
          "value": 25,
          "currency": "USD"
        }
      }
    ]
    "searchs": ""
  }
}

and i want to search these datas by activity type. i tried nested queries like

"query": {
  "nested": {
     "path": "activity",
     "query": {
         "bool": {
             "must": [
                {"match": {
                   "activity.type": "outdoor"
                }}
           ]
       }
   }
}

and like

"query": {
  "nested": {
    "path": "activity",
    "query": {
      "nested": {
        "path": "type",
        "query": {
           "bool": {
               "must": [
                  {"match": {
                     "type.value": "outdoor"
                  }}
               ]
           }
        }
      }
    }
  }
}

but i couldn't succeed.

How can i search these datas by activity type?

1 Answer 1

1

You can use a simple match query if you're just looking for records with an activity type like

{
  "query": {
    "match": {
      "activity.type": "Outdoor"
    }
  }
}
Sign up to request clarification or add additional context in comments.

5 Comments

When i use this. i can get only first acitivity's type records which has multiple activity for example when i run this query i can't get "Jane Doe" record.
Are you sure there are 2 records on your index? And that when you are querying, you're not specifying a page size of 1? You can try using a plugin like head to browse your index.
yes i'm sure i have larg amount of data but i sampled 15 example for trying. when i run query it doesn't gets users with multiple activities.
Can you display the output you get when running the query above?
Oh i found the error. it doesn't found because of charset error on my console. Thank you.

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.