Elasticsearch 按词项term查询和match查询 朱雀 2022-11-11 05:12 149阅读 0赞 按词项(term)查询,查询参数不会进行分词,且作为一个整体,由于文档索引时候进行了分词,有可能查询不到。如果使用词项查询keyword字段,keyword字段使用keyword分词器,分词前后内容一致,如果用索引时候内容查询key查询到。 1 初始化数据 DELETE test PUT test/_doc/1 { "content":"Hello World" } 2 match查询 参数会分词 索引会分词 可以查询到 POST test/_search { "profile": "true", "query": { "match": { "content": "Hello World" } } } 3 match查询 参数会分词 索引会分词 可以查询到 POST test/_search { "profile": "true", "query": { "match": { "content": "hello world" } } } 4 match查询 keyword字段在索引查询时候分词内容不变 能查询到 POST test/_search { "profile": "true", "query": { "match": { "content.keyword": "Hello World" } } } 5 matchh查询 索引时候keyword内容是大写 查询时候是小写 无法查询到 POST test/_search { "profile": "true", "query": { "match": { "content.keyword": "hello world" } } } 6 基于term查询 查询参数不分词 文档索引进行了分词 查询不到 POST test/_search { "profile": "true", "query": { "term": { "content": "Hello World" } } } 7 基于term查询 参数是一个整体 文档索引时候进行了分词 查询不到 POST test/_search { "profile": "true", "query": { "term": { "content": "hello world" } } } 8 基于term查询 查询字段keyword字段不分词 索引时候keyword字段也没有分词 可以查询到 POST test/_search { "profile": "true", "query": { "term": { "content.keyword": "Hello World" } } }
还没有评论,来说两句吧...