【问题标题】:results not showing during indexing elastic search索引弹性搜索期间未显示结果
【发布时间】:2020-07-28 20:09:38
【问题描述】:

我正在使用批量请求执行弹性搜索完整索引。我在索引过程中遇到问题,结果是空的。当我在完整索引期间删除索引时,我该如何处理这种情况。

我已经完成了这些步骤:

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

索引属性和映射:

{
"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 个文档。

谢谢, 斯里。

【问题讨论】:

  • 请显示您通过运行GET your-index-name获得的索引设置和映射
  • 你在使用 Spring Data Elatsicsearch 吗?如果是这样,它的哪个版本,以及 Elasticsearch 的哪个版本?如何在不创建索引的情况下创建映射?
  • @P.J.Meisch 抱歉删除索引后我正在创建映射然后映射。
  • @Val 添加了设置和映射

标签: elasticsearch spring-data-elasticsearch


【解决方案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

这样您就可以在用户没有注意到任何事情的情况下重新编制索引。

【讨论】:

  • 搜索请求如何知道别名?我是否需要使用新的别名更改所有请求?
  • 是的,您可以将搜索请求更改为使用别名而不是索引名称。
  • 对不起,我很困惑,请您提供更多输入。每次都很难更改代码中的别名。假设我每天运行一次完整索引。你想更改代码中还有别名?
猜你喜欢
  • 2021-02-23
  • 1970-01-01
  • 2021-07-12
  • 2023-04-07
  • 2021-09-24
  • 1970-01-01
  • 1970-01-01
  • 2011-05-10
相关资源
最近更新 更多