Elasticsearch或条件这种写法为什么查不出数据?

我想搜类似 select * from table where title like "%中国行%" or doc_content like "%中国行%";
下面这句有啥问题吗?查不出内容。

192.168.33.10:9200/test/_search?pretty
{
    "query": {
        "bool": {
            "should": [
                {
                    "term": {
                        "title": "中国行"
                    }
                },
                {
                    "term": {
                        "doc_content": "中国行"
                    }
                }
            ]
        }
    }
}
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}
阅读 2.3k
1 个回答
新手上路,请多包涵

term是精确匹配,达不到mysql中like的效果,如果你要模糊匹配,应该用match,match会对文本进行分词然后匹配查询:
192.168.33.10:9200/test/_search?pretty
{

"query": {
    "bool": {
        "should": [
            {
                "match": {
                    "title": "中国行"
                }
            },
            {
                "match": {
                    "doc_content": "中国行"
                }
            }
        ]
    }
}

}

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进