简体   繁体   中英

Elasticsearch query to filter based on list

Let us say we have following lists in ES. (Each list is part of separate document)

[1], [2], [1, 2], [1, 2, 3, 4]

If we query with the list [1, 2] , ES should return below results only.

[1], [2], [1, 2]

Note that using ' terms query ', will return [1, 2, 3, 4] also which is not the intended result.

Could someone suggest ES query for this scenario?

if the object is mapped as Nested datatype you can search something like listValue is 1, and also is 2, it will result on [1, 2] or [2, 1] because ES doesn't handle orders in simple arrays.

The nested type is a specialised version of the object datatype that allows arrays of objects to be indexed in a way that they can be queried independently of each other.

https://www.elastic.co/guide/en/elasticsearch/reference/6.3/nested.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM