Contact tracing, a transmission intervention, has shown effectiveness inpandemic control. However, most existing schemes only focus on direct contact. There has been little work on indirect contact. In addition,most schemes are too stereotypical to change the rules of “contact” flexibly. To address the above problems, this paper provides flexible contact tracing mining (FCTM) algorithms for moving objects. First, a contact tracing model that supports four scenarios of contact identification is presented. Then, a baseline contact tracing mining algorithm(FCTMbas) using sliding window mechanism is proposed. To further improve the mining performance, an optimization contact tracing mining algorithm (FCTMopt) based on binary anchor timestamp (BAT)is proposed. It processes all objects only at BATs and quickly prunes detection objects at a safe distance from infected objects. We comprehensively evaluate the performance of our algorithms on real-world datasets. The results showed that they could mine more contacts and the optimization algorithm FCTMopt is more efficient than FCTMbas.