Solr: Retrieve field names from a solr index?

前端 未结 3 1531
借酒劲吻你
借酒劲吻你 2020-12-29 22:17

How can I query a Solr instance for all (or prefixed) field names?

I want to use dynamic fields where I do not know how many may exist e.g: category_0_s,

3条回答
  •  情深已故
    2020-12-29 22:35

    If you need to do this from your Java application you can use Solrj and LukeRequestRequestHandler.

    Your code would look like this.

    LukeRequest lukeRequest = new LukeRequest();
    lukeRequest.setNumTerms(0);
    
    LukeResponse lukeResponse = lukeRequest.process(server);
    
    Map fieldInfoMap = lukeResponse.getFieldInfo();
    
    for (Entry entry : fieldInfoMap.entrySet()) {
    
        String fieldName = entry.getKey();
        FieldInfo fieldInfo = entry.getValue();
    
        // process fieldInfo    
    }
    

提交回复
热议问题