Filter array


(Vitalii) #1

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


(Makoto Nozawa) #2

Hi,

How about this filter?

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

(Vitalii) #3

i tried but it doesn't work too


(Makoto Nozawa) #4

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

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

(Makoto Nozawa) #5

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


(Vitalii) #6
{"prof": {
      "location": {
        "properties": {
          "city": {
            "type": "string"
          },
          "id": {
            "type": "long"
          }
        }
      },
      "rank": {
        "properties": {
          "id": {
            "type": "string"
          }
        }
    }
  }
}

(Vitalii) #8

guys maybe someone know how do search?


(Makoto Nozawa) #9

In my environment(ES2.3.), this works... :thinking:
(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" }}
      ] 
    }
  }
}

(Vitalii) #10

thx!!!


(system) #11

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