索引弹性搜索期间未显示结果

时间:2020-07-27 02:27:07

标签: elasticsearch spring-data-elasticsearch

我正在使用批量请求执行弹性搜索全索引。在索引编制过程中出现问题,结果显示为空。当我在完整索引期间删除索引时,如何处理这种情况。

我已经完成了以下步骤:

  • 删除索引
  • 创建索引
  • 创建映射
  • 批量请求

索引属性和映射:

{
"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"
            }
        }
    }
}

}

我有大约75,000个文档。

谢谢, 斯里。

1 个答案:

答案 0 :(得分:1)

如果希望完整索引在重新索引期间可用,则唯一的选择是在完成索引编制后才删除原始索引。在这种情况下,我可能会使用aliases。例如,假设products-2020.07.28是当前索引,那么您将为今天创建一个新索引,并在完成索引后立即更改别名。

  • 创建索引

    PUT /products-2020.07.28
    {
      "settings": {
        ... your settings ...
      },
      "mappings": {
        ... your mappings ...
      }
    }
    
  • 批量索引请求

  • 将别名更改为新索引

    POST /_aliases
    {
      "actions" : [
        { "remove" : { "index" : "products-2020.07.27", "alias" : "products" } },
        { "add" : { "index" : "products-2020.07.28", "alias" : "products" } }
      ]
    }
    
  • 删除旧索引

    DELETE /products-2020.07.27
    

然后,任何请求都可以直接转到别名,而不是索引。

GET /products/_search

这样,您无需用户注意即可重新编制索引。