elasticsearch filter by length of a string field

后端 未结 2 2003
感情败类
感情败类 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条回答
  • 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"
              }
          }
    }
    
    0 讨论(0)
  • 2021-01-12 21:56

    You can also use custom tokenizers to count the number of characters. Check this answer for a possible help: https://stackoverflow.com/a/47556098/463846

    0 讨论(0)
提交回复
热议问题