Search code examples
elasticsearchspring-data-elasticsearch

results not showing during indexing elastic search


I am performing elastic search full indexing using Bulk request. I have an issue during the indexing the results are coming as empty. As I am deleting the index during the full index, How I can handle this situation.

I have done the these steps:

  • delete index
  • Create index
  • Create Mapping
  • bulk request

Index properties and Mapping:

{
"products": {
    "aliases": {},
    "mappings": {
        "properties": {
            "assemblyrequired": {
                "type": "boolean"
            },
            "australianmade": {
                "type": "boolean"
            },
            "australiasellable": {
                "type": "boolean"
            },
            "avgRating": {
                "type": "float"
            },
            "category": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "categorylevel1": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "categorylevel2": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "categorylevel3": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "categoryname": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "categoryname_old": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "clearance": {
                "type": "boolean"
            },
            "commercialuse": {
                "type": "boolean"
            },
            "customisable": {
                "type": "boolean"
            },
            "depth": {
                "type": "float"
            },
            "freedelivery": {
                "type": "boolean"
            },
            "genericcolourcode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "height": {
                "type": "float"
            },
            "hideprice": {
                "type": "boolean"
            },
            "listprice": {
                "type": "float"
            },
            "materialcode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "moneybackguarantee": {
                "type": "boolean"
            },
            "newrelease": {
                "type": "boolean"
            },
            "numberOfRating": {
                "type": "long"
            },
            "online": {
                "type": "boolean"
            },
            "outdooruse": {
                "type": "boolean"
            },
            "predictivecategorydata": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "pricematchguarantee": {
                "type": "boolean"
            },
            "productcode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "productid": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "productimageurl": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "productname": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "producttypecode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "promotedprice": {
                "type": "float"
            },
            "sale": {
                "type": "integer"
            },
            "saleprice": {
                "type": "float"
            },
            "sellable": {
                "type": "boolean"
            },
            "sellercode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "shortdescription": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "sku": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "sortweight": {
                "type": "long"
            },
            "state": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "stylecode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "warrantycode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "weight": {
                "type": "float"
            },
            "width": {
                "type": "float"
            }
        }
    },
    "settings": {
        "index": {
            "number_of_shards": "1",
            "provided_name": "products",
            "max_result_window": "500000",
            "creation_date": "1595814303422",
            "number_of_replicas": "1",
            "uuid": "sGJxwr73Rkyu7-JekWFYsw",
            "version": {
                "created": "7060199"
            }
        }
    }
}

}

I have around 75k documents.

Thanks, Sree.


Solution

  • If you want the full index to be available during the reindex, your only option is to not delete the original index until after the indexing is done. In that case, I would probably work with aliases. For example, let's assume products-2020.07.28 was your current index, you would then create a new index for today and change the alias as soon as the indexing is done.

    • Create Index

      PUT /products-2020.07.28
      {
        "settings": {
          ... your settings ...
        },
        "mappings": {
          ... your mappings ...
        }
      }
      
    • Bulk Index Request

    • Change Alias to new Index

      POST /_aliases
      {
        "actions" : [
          { "remove" : { "index" : "products-2020.07.27", "alias" : "products" } },
          { "add" : { "index" : "products-2020.07.28", "alias" : "products" } }
        ]
      }
      
    • Delete old Index

      DELETE /products-2020.07.27
      

    Any requests can then go directly to the alias, instead of the index.

    GET /products/_search
    

    That way you can reindex without the user noticing anything.