how to filter search by values that are not available

后端 未结 5 2396
逝去的感伤
逝去的感伤 2021-02-20 06:11

I have a list of items as:

i = SearchQuerySet().models(Item)

now, each item in i has a attribute, price

I wan

5条回答
  •  难免孤独
    2021-02-20 06:59

    The double negated query suggested by Maurizio may cause error:

    unexpected docvalues type NUMERIC for field 'price' (expected one of [SORTED, SORTED_SET]). Re-index with correct docvalues type.
    

    (Even after re-indexing. This may have something to do with the index and store and docvalues settings of the field.)

    What you could do instead is exempt both ranges (before and after) of the values you are actually interested in:

    -(price:[* TO 300} price:{400 TO *])
    

    Note that values 300 and 400 are excluded by using curly brackets in this negated query and are thus included in the search results.

提交回复
热议问题