title: Matching arrays in elastic search
body: <p>I have document as below:</p>
  
  <pre><code>{
      "_index": "abc_local",
      "_type": "users",
      "_id": "1",
      "_version": 5,
      "found": true,
      "_source": {
          "firstname": "simer",
          "lastname": "kaur",
          "gender": "1",
          "Address": "Punjab House Fed. Housing Society, Amritsar, Punjab, India",
          "email": "rav@yopmail.com",
          "occupation": "Php Developer",
          "work": "Development",
          "fav_hunting_land": 2,
          "zipcode": "",
          "marital_status": "1",
          "phone": "1234567899",
          "school": "sdfergdfh",
          "species": [{
              "id": 1
          }, {
              "id": 2
          }, {
              "id": 3
          }, {
              "id": 4
          }, {
              "id": 5
          }, {
              "id": 6
          }],
          "activities": [{
              "id": 1
          }],
          "fav_weapon": 6,
          "weapons": [{
              "id": 1
          }, {
              "id": 2
          }, {
              "id": 3
          }, {
              "id": 6
          }],
          "properties": [{
              "id": 4
          }]
      }
  }
  </code></pre>
  
  <p>and I need to match user on basis of weapons and I am trying something like:</p>
  
  <pre><code>$params = [
              'index' =&gt; Constants::INDEX,
              'type' =&gt; Constants::DOC_TYPE_USERS,
              'body' =&gt; [
                  "query"=&gt; [
                      "bool"=&gt; [
                          "must"=&gt;   [ "match"=&gt; [ "weapons.id"=&gt;$params['weapons'] ]],
  
                          "should"=&gt; [
                                      [ "match"=&gt; [ "firstname"=&gt; $params['search_text'] ]],
                                      [ "match"=&gt; [ "lastname"=&gt; $params['search_text']   ]]
                                          ]
                                      ]
                              ]
                          ]
  
                  ];
  </code></pre>
  
  <p>as I am using elastic in PHP. Here $params['weapons'] is:</p>
  
  <pre><code>array (size=2)
    0 =&gt; string '1' (length=1)
    1 =&gt; string '2' (length=1)
  </code></pre>
  
  <p>I get an error:</p>
  
  <blockquote>
    <p>illegal_state_exception: Can't get text on a START_ARRAY at 1:36</p>
  </blockquote>
  
  <p>Any suggestions/help would be appreciated that how I can match array. I took reference from <a href="https://www.elastic.co/guide/en/elasticsearch/reference/2.1/nested.html" rel="noreferrer">nested datatypes</a></p>
  
  <p><strong>Update#1</strong>:
  parameters I am sending to my function: <code>{"from":0,"size":null,"city":null,"state":"0","weapons":["1","2"],"activities":[],"species":[],"properties":[],"search_text":"lastname"}</code></p>
  
  <p><strong>update#2</strong>:
  Body of my query in json format:</p>
  
  <pre><code>{
      "index": "abc_local",
      "type": "users",
      "body": {
          "query": {
              "bool": {
                  "must": {
                      "match": {
                          "weapons.id": ["1", "2"]
                      }
                  },
                  "should": [{
                      "match": {
                          "firstname": "simer"
                      }
                  }, {
                      "match": {
                          "lastname": "simer"
                      }
                  }]
              }
          }
      }
  }
  </code></pre>