E
E
ErickSkrauch2015-07-30 15:37:23
elasticsearch
ErickSkrauch, 2015-07-30 15:37:23

How to select an element from elasticsearch that has exactly the same array value?

Suppose the model has a list of fields and one of them is a list of id of some related fields:

{
    'name': 'bla-bla',
    'field1': 'value1',
    'array': [
        1, 2, 3, 4
    ]
}

It is necessary to select those records whose array values ​​match the passed id set, i.e. if I pass 1, 2, 3 , or vice versa 1, 2, 3, 4, 5 , then the line will not be found, but if I pass 3, 2, 4, 1 (i.e. the order does not decide), then the line will be found .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
un1t, 2015-07-30
@un1t

I don't know if it will work in your case, you can put an additional field into the index,
your [1,2,3,4] will be converted, for example, into the string "1-2-3-4". Those. when indexing and querying, we sort and join.

M
MintTea, 2015-08-06
@MintTea

Something like this ( And filter + Term filter ):

curl -XGET 'http://localhost:9200/index_name/type_name/_search?pretty' -d '{
    "filter": {
        "and": [
            {"term": {"field_name": 1}},
            {"term": {"field_name": 2}},
            {"term": {"field_name": 3}},
            {"term": {"field_name": 4}}
        ]
    }
}'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question