2015-03-29 3 views
6

समस्या:Elasticsearch जावा एपीआई addMapping() और setSettings() उपयोग

json फ़ाइल का उपयोग करते हुए एक json फ़ाइल से एक सूचकांक बनाने के लिए कैसे सूचकांक de_brochures के लिए एक परिभाषा में शामिल है। यह एक विश्लेषक de_analyzer को संबंधित फ़िल्टर द्वारा उपयोग किए जाने वाले कस्टम फ़िल्टर के साथ भी परिभाषित करता है। जैसा कि जेसन कर्ल और सेंस के साथ काम करता है, मुझे लगता है कि जावा जावा एपीआई के साथ काम करने के लिए मुझे इसके सिंटैक्स को अनुकूलित करना होगा।

मैं XContentFactory.jsonBuilder() का उपयोग नहीं करना चाहता क्योंकि जेसन एक फ़ाइल से आता है! indexname यह इस से एक सूचकांक पैदा नहीं करता

PUT साथ नब्ज का उपयोग /:

मैंने अपने मानचित्रण नहीं बना और सेटिंग सेट करने के लिए निम्न json फ़ाइल है।

{ 
    "mappings": { 
    "de_brochures": { 
     "properties": { 
     "text": { 
      "type": "string", 
      "store": true, 
      "index_analyzer": "de_analyzer" 
     }, 
     "classification": { 
      "type": "string", 
      "index": "not_analyzed" 
     }, 
     "language": { 
      "type": "string", 
      "index": "not_analyzed" 
     } 
     } 
    } 
    "settings": { 
    "analysis": { 
     "filter": { 
     "de_stopwords": { 
      "type": "stop", 
      "stopwords": "_german_" 
     }, 
     "de_stemmer": { 
      "type": "stemmer", 
      "name": "light_german" 
     } 
     }, 
     "analyzer": { 
     "de_analyzer": { 
      "type": "custom", 
      "tokenizer": "standard", 
      "filter": [ 
      "lowercase", 
      "de_stopwords", 
      "de_stemmer" 
      ] 
     } 
     } 
    } 
    } 
} 

ऊपर addMapping() के साथ काम नहीं किया जैसा कि अकेले मैं इसे दो अलग फ़ाइलों में विभाजित करने की कोशिश की (मुझे एहसास हुआ कि मैं "mappings": और "settings": हिस्से को हटाने के लिए किया था):

------ Mapping json ------ 
{ 
    "de_brochures": { 
    "properties": { 
     "text": { 
     "type": "string", 
     "store": true, 
     "index_analyzer": "de_analyzer" 
     }, 
     "classification": { 
     "type": "string", 
     "index": "not_analyzed" 
     }, 
     "language": { 
     "type": "string", 
     "index": "not_analyzed" 
     } 
    } 
    } 
} 
------- Settings json -------- 
{ 
    "analysis": { 
    "filter": { 
     "de_stopwords": { 
     "type": "stop", 
     "stopwords": "_german_" 
     }, 
     "de_stemmer": { 
     "type": "stemmer", 
     "name": "light_german" 
     } 
    }, 
    "analyzer": { 
     "de_analyzer": { 
     "type": "custom", 
     "tokenizer": "standard", 
     "filter": [ 
      "lowercase", 
      "de_stopwords", 
      "de_stemmer" 
     ] 
     } 
    } 
    } 
} 

यह मेरा जावा कोड लोड करने और जेसन को जोड़ने/सेट करने के लिए है।

CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(index); 
// CREATE SETTINGS 
String settings_json = new String(Files.readAllBytes(brochures_mapping_path)); 
createIndexRequestBuilder.setSettings(settings_json); 
// CREATE MAPPING 
String mapping_json = new String(Files.readAllBytes(brochures_mapping_path)); 
createIndexRequestBuilder.addMapping("de_brochures", mapping_json); 
CreateIndexResponse indexResponse = createIndexRequestBuilder.execute().actionGet(); 

मैपिंग फ़ाइल की संरचना के बारे में कोई अधिक शिकायत नहीं है लेकिन अब यह त्रुटि के साथ विफल:

Caused by: org.elasticsearch.index.mapper.MapperParsingException: Analyzer [de_analyzer] not found for field [text] 

उत्तर

4

समाधान: मैं अपने मूल json का उपयोग कर फ़ाइल के साथ यह करने के लिए प्रबंधित createIndexRequestBuilder.setSource(settings_json);

+0

कृपया प्रश्न का समाधान जोड़ें न करें। समाधान प्रश्न नहीं हैं। समाधान जवाब हैं। जब आप समाधान पाते हैं तो स्टैकओवरफ्लो आपके प्रश्नों का उत्तर देने का प्रोत्साहित करता है। लेकिन कृपया इसे एक जवाब में करें। समाधान को शामिल करने के लिए सवाल को संपादित करना सिर्फ पाठकों को भ्रमित करता है। धन्यवाद! – Vogel612

1

मुझे लगता है कि समस्या अपने मैपिंग फ़ाइल की संरचना के साथ है।

यहां एक नमूना उदाहरण है।

mapping.json 
{ 
"en_brochures": { 
    "properties": { 
     "text": { 
      "type": "string", 
      "store": true, 
      "index_analyzer": "en_analyzer", 
      "term_vector": "yes" 
     }, 
     "classification": { 
      "type": "string", 
      "index": "not_analyzed" 
     }, 
     "language": { 
      "type": "string", 
      "index": "not_analyzed" 
     } 
    } 
    } 
} 



String mapping = new String(Files.readAllBytes(Paths.get("mapping.json"))); 
    createIndexRequestBuilder.addMapping('en_brochures', mapping); 
    CreateIndexResponse indexResponse =createIndexRequestBuilder.execute().actionGet(); 

यह मेरा काम करता है, आप कोशिश कर सकते हैं।

+0

क्या आपको पता है कि कैसे मैं यह काम करने के लिए अपने json संरचना में "विश्लेषक" भाग में फिट कर सकते हैं है? – Peter

+0

देखो! मैंने बदल दिया है, मेरा जवाब। और, इसके लिए काम करने के लिए आपको सेटिंग्स जोड़ना होगा (जैसा आपने पहले किया था) – progrrammer

+0

मुझे लगता है कि आप पहले से ही en_analyzer जोड़ चुके हैं? आपने ऐसा कैसे किया? अन्यथा यह "पाठ" के लिए "en_analyzer" नहीं ढूंढने के बारे में शिकायत करता है। – Peter