# Filter array

**URL:** <https://discuss.elastic.co/t/filter-array/73952>\
**Category:** Elasticsearch\
**Created:** [February 4, 2017, 4:51pm UTC](https://discuss.elastic.co/t/filter-array/73952 "2017-02-04T16:51:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![fix2015](https://avatars.discourse-cdn.com/v4/letter/f/aca169/32.png) [@fix2015](https://discuss.elastic.co/u/fix2015)\
**Post date:** [February 4, 2017, 4:51pm UTC](https://discuss.elastic.co/t/filter-array/73952/1 "2017-02-04T16:51:43Z")

</div>

hey guys, i have pb,  
i have this field  
"rank": {  
"properties": {  
"id": {  
"type": "string"  
}  
}  
it return array and i need filter it  
try like this  
{  
"filter": { "term": { "rank": "jun" } },  
"random\_score": {},  
"weight": 150  
},  
but it doesn't help

---

<div class="post-metadata">

**Author:** ![mnozawa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mnozawa/32/15091_2.png) [@mnozawa](https://discuss.elastic.co/u/mnozawa)\
**Post date:** [February 4, 2017, 5:20pm UTC](https://discuss.elastic.co/t/filter-array/73952/2 "2017-02-04T17:20:49Z")

</div>

Hi,

How about this filter?

```
{
"filter": { "term": { "rank.id": "jun" } }
}
```

---

<div class="post-metadata">

**Author:** ![fix2015](https://avatars.discourse-cdn.com/v4/letter/f/aca169/32.png) [@fix2015](https://discuss.elastic.co/u/fix2015)\
**Post date:** [February 4, 2017, 5:23pm UTC](https://discuss.elastic.co/t/filter-array/73952/3 "2017-02-04T17:23:11Z")

</div>

i tried but it doesn't work too

---

<div class="post-metadata">

**Author:** ![mnozawa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mnozawa/32/15091_2.png) [@mnozawa](https://discuss.elastic.co/u/mnozawa)\
**Post date:** [February 4, 2017, 5:40pm UTC](https://discuss.elastic.co/t/filter-array/73952/4 "2017-02-04T17:40:12Z")

</div>

Sorry, I made mistake in syntax.  
How about this?

```
GET /_search
{
  "query": { 
    "bool": { 
      "filter": [ 
        { "term": { "rank.id": "jun" }}
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![mnozawa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mnozawa/32/15091_2.png) [@mnozawa](https://discuss.elastic.co/u/mnozawa)\
**Post date:** [February 4, 2017, 5:42pm UTC](https://discuss.elastic.co/t/filter-array/73952/5 "2017-02-04T17:42:19Z")

</div>

If it not works again, please tell me your whole Mapping?

```
GET /YOUR_INDEX_NAME/_mappings

```

[https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html)

---

<div class="post-metadata">

**Author:** ![fix2015](https://avatars.discourse-cdn.com/v4/letter/f/aca169/32.png) [@fix2015](https://discuss.elastic.co/u/fix2015)\
**Post date:** [February 4, 2017, 5:50pm UTC](https://discuss.elastic.co/t/filter-array/73952/6 "2017-02-04T17:50:44Z")

</div>

```
{"prof": {
      "location": {
        "properties": {
          "city": {
            "type": "string"
          },
          "id": {
            "type": "long"
          }
        }
      },
      "rank": {
        "properties": {
          "id": {
            "type": "string"
          }
        }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![fix2015](https://avatars.discourse-cdn.com/v4/letter/f/aca169/32.png) [@fix2015](https://discuss.elastic.co/u/fix2015)\
**Post date:** [February 5, 2017, 10:00am UTC](https://discuss.elastic.co/t/filter-array/73952/8 "2017-02-05T10:00:58Z")

</div>

guys maybe someone know how do search?

---

<div class="post-metadata">

**Author:** ![mnozawa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mnozawa/32/15091_2.png) [@mnozawa](https://discuss.elastic.co/u/mnozawa)\
**Post date:** [February 6, 2017, 5:09am UTC](https://discuss.elastic.co/t/filter-array/73952/9 "2017-02-06T05:09:43Z")

</div>

In my environment(ES2.3.), this works... 🤔  
(Because of _string_ field (not _text_), I expected that it is ES 2.x.)

```
// create index
PUT test_index
{
  "mappings": {
    "prof": {
      "properties": {
        "location": {
          "properties": {
            "city": {
              "type": "string"
            },
            "id": {
              "type": "long"
            }
          }
        },
        "rank": {
          "properties": {
            "id": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}

// index a document
PUT test_index/prof/1
{
  "location": {
    "city": "sample",
    "id": 1
  },
  "rank": {
    "id": "sample2"
  }
}

// search
GET test_index/prof/_search
{
  "query": { 
    "bool": { 
      "filter": [ 
        { "term": { "rank.id": "sample2" }}
      ] 
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![fix2015](https://avatars.discourse-cdn.com/v4/letter/f/aca169/32.png) [@fix2015](https://discuss.elastic.co/u/fix2015)\
**Post date:** [February 6, 2017, 6:56pm UTC](https://discuss.elastic.co/t/filter-array/73952/10 "2017-02-06T18:56:48Z")

</div>

thx!!!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 6, 2017, 6:57pm UTC](https://discuss.elastic.co/t/filter-array/73952/11 "2017-03-06T18:57:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
