Elasticsearch: filter => query
put wares { "settings":{ "number_of_shards": 1, "number_of_replicas":0 }, "mappings":{ "properties":{ "id":{ "type":"integer" }, "title":{ "type": "keyword" }, "price":{ "type":"double" }, "create_at":{ "type":"date" }, "description":{ "type":"text", "analyzer": "ik_max_word" } } } } get _cat/indices?v get wares/_mapping delete orders # 手动指定_id post wares/_doc/1 { "id": 1, "title": "小浣熊", "price": 0.5, "create_at": "2022-11-02", "description": "小浣熊真好吃" } post wares/_doc/2 { "id": 2, "title": "鱼豆腐", "price": 4.8, "create_at": "2022-11-02", "description": "鱼豆腐很不错,真好吃rtyu uiop" } # 自动生成_id post wares/_doc { "id": 3, "title": "日本豆", "price": 1.8, "create_at": "2022-11-02", "description": "日本豆很不错" } post wares/_doc { "id": 4, "title": "红烧排骨鱼翅", "price": 7.8, "create_at": "2022-10-02", "description": "红烧排骨鱼翅, 这个菜很独特" } post wares/_doc { "id": 4, "title": "红烧排骨鱼翅", "price": 7.8, "create_at": "2022-10-02", "description": "红烧排骨鱼翅, 这个菜很独特,好吃好吃" } get valian/_search { "query":{ "term":{ "description": { "value": "好吃" } } } } get valian/_search { "query":{ "bool":{ "must": [ { "term":{ "description": {"value": "好吃"} } } ] } } } # filter term get valian/_search { "query":{ "bool":{ "must": [ { "match_all": {} } ], "filter": [ { "term":{ "description": {"value": "很"} } } ] } } } # filter terms get valian/_search { "query":{ "bool":{ "must": [ { "match_all": {} } ], "filter": [ { "terms":{ "description": ["好吃","日本"] } } ] } } } # filter range get valian/_search { "query":{ "bool":{ "must": [ { "match_all": {} } ], "filter": [ { "range": { "price": { "gte": 0, "lte": 4 } } } ] } } } # filter exists get valian/_search { "query":{ "bool":{ "must": [ { "match_all": {} } ], "filter": [ { "exists": { "field": "price" } } ] } } } # filter ids get valian/_search { "query":{ "bool":{ "must": [ { "match_all": {} } ], "filter": [ { "ids":{ "values": [1,2] } } ] } } } get valian/_search { "query":{ "bool":{ "must": [ { "term":{ "description": {"value": "好吃"} } } ], "filter": [ { "term":{ "description": {"value": "很"} } } ] } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!