elasticsearch filter by length of a string field

后端 未结 2 2022
感情败类
感情败类 2021-01-12 21:25

i am trying to get records the has in \'title\' more then X characters.

NOTE: not all records contains title field.

i have tried:

GET books/_         


        
2条回答
  •  萌比男神i
    2021-01-12 21:51

    You need to take into account that some documents might have a null title field. So you can use the groovy null-safe operator. Also make sure to use the POST method instead:

    POST books/_search
    {
        "filter" : {
              "script" : {
                  "script" : "_source.title?.size() > 10"
              }
          }
    }
    

提交回复
热议问题