In recent years, the number of sensor and actuator nodes in the Internet of Things (IoT) networks has increased, generating a large amount of data. Most research techniques are based on dividing target data into subsets. On a large scale, this volume increases exponentially, which will affect search algorithms. This problem is caused by the inherent deficiencies of space partitioning. This paper introduces a new and efficient indexing structure to index massive IoT data called BCCF-tree (Binary tree based on containers at the cloud-fog computing level). This structure is based on recursive partitioning of space using the k-means clustering algorithm to effectively separate space into nonoverlapping subspace to improve the quality of search and discovery algorithm results. A good topology should avoid a biased allocation of objects for separable sets and should not influence the structure of the index. BCCF-tree structure benefits to the emerging cloud-fog computing system, which represents the most powerful real-time processing capacity provided by fog computing due to its proximity to sensors and the largest storage capacity provided by cloud computing. The paper also discusses the effectiveness of construction and search algorithms, as well as the quality of the index compared to other recent indexing data structures. The experimental results showed good performance.