使用Elasticsearch进行查询时遇到麻烦

问题描述 投票:0回答:2

朋友们,我希望您在这个流行时期过得不错,在Elasticsearch的查询中忽略特殊字符时遇到了麻烦:这是我想做的:

Select * from table where ext like %6500% and start_time like %-01-% 

这是我所做的:

   "query": {
       "bool": {
           "must": [
               {
                   "query_string": {
                       "ext": "*6500*",
                       "fields": [
                           "extension"
                       ],
                       "analyze_wildcard": true
                   }
               },
               {
                   "query_string": {
                       "query": "*\\-01\\-*",
                       "fields": [
                           "start_time"
                       ],
                       "analyze_wildcard": true
                   }
               }
           ]
       }
   }

第一个有效,但第二个没有满足我的需求。顺便说一句,字段start_time就像这样:2020-01-03 15:03:45,这是一个heyword类型(我发现是这样)。

elasticsearch wildcard sql-like elasticsearch-dsl elasticsearch-api
2个回答
0
投票

您正在使用文本类型的字段和关键字类型的子字段来索引字段。令牌中的文本字段已损坏,例如“ 2020-01-12”将被存储为[“ 2020”,“ 01”,“ 12”]。您需要使用“ start_time.keyword”


0
投票

如果您被迫在keyword中使用start_time类型,则以下工作-不需要前导和尾部通配符,因为您的start_time将遵循某种格式:

© www.soinside.com 2019 - 2024. All rights reserved.