undefinedfix
Sign in

Why can't elastic search or conditional search find data?

savemightlife edited in Wed, 02 Nov 2022

I'd like to search for something like "select * from table where title like"% "or doc_ What's wrong with the following sentence? We can't find out the content.

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": []
  }
}
1 Replies
M_Salehi
commented on Thu, 03 Nov 2022

Term is accurate matching, which can't achieve the effect of like in MySQL. If you want fuzzy matching, you should use match, which will segment the text and then match the query: 192.168.33.10:9200/test/_ search?pretty{

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

}