2017-06-03 11 views
1

階層構造を保持した列を持つデータフレームにクエリ結果を取得するにはどうすればよいですか?ElasticSearch-JSONファイルからPythonにデータを取得する

type|postDate|discussionTitle|courses|subjectKeywords|SentiStrength|SentiWordNet|universities|universityKeywords| 

私は約1,000,000個のJSOnドキュメントを持つelasticSearchを持っています。 Pythonで自然言語処理(NLP)にこのデータセットを使用したいと思います。 誰かがelasticsearchからPythonにデータを取得し、Pythonからelasticsearchにデータを書き戻す方法を教えてください。 私はPythonに接続することができないので、私が持っているデータセットでNLPを行うことができずに立ち往生しています。 elasticsearchのインデックス構造は次のようになります。
「大学情報」のように新しい情報を「プロセス情報」 と同じように入力すると、この新しいインデックスによって一連のキーワードは "universityKeywords"と同じように、すべてのjasonファイルはタグが使用するキーワードのセットを格納する必要があります。私は、「プロセス情報」へのデータセットをタグ付けしたい は - JSONファイルnamed-アプリケーション、申し出、加入契約、JSONファイルポストタイトルにキーワードに基づいて、要件の4個のタグやカテゴリーを入れて、テキスト

"educationforumsenriched2": { 
      "mappings": { 
      "whirlpool": { 
       "properties": { 
        "CourseInfo": { 
         "properties": { 
         "courses": { 
          "type": "string", 
          "index": "not_analyzed" 
         }, 
         "subjectKeywords": { 
          "type": "string", 
          "index": "not_analyzed" 
         } 
         } 
        }, 
        "SentimentInfo": { 
         "properties": { 
         "SentiStrength": { 
          "type": "float" 
         }, 
         "SentiWordNet": { 
          "type": "float" 
         } 
         } 
        }, 
        "UniversityInfo": { 
         "properties": { 
         "universities": { 
          "type": "string", 
          "index": "not_analyzed" 
         }, 
         "universityKeywords": { 
          "type": "string", 
          "index": "not_analyzed" 
         } 
         } 
        }, 
        "postDate": { 
         "type": "date", 
         "format": "strict_date_optional_time||epoch_millis" 
        }, 
        "postID": { 
         "type": "integer" 
        }, 
        "postText": { 
         "type": "string" 
        }, 
        "references": { 
         "type": "string" 
        }, 
        "threadID": { 
         "type": "integer" 
        }, 
        "threadTitle": { 
         "type": "string" 
        } 
       } 
      }, 
      "atarnotes": { 
       "properties": { 
        "CourseInfo": { 
         "properties": { 
         "courses": { 
          "type": "string", 
          "index": "not_analyzed" 
         }, 
         "subjectKeywords": { 
          "type": "string", 
          "index": "not_analyzed" 
         } 
         } 
        }, 
        "SentimentInfo": { 
         "properties": { 
         "SentiStrength": { 
          "type": "float" 
         }, 
         "SentiWordNet": { 
          "type": "float" 
         } 
         } 
        }, 
        "UniversityInfo": { 
         "properties": { 
         "universities": { 
          "type": "string", 
          "index": "not_analyzed" 
         }, 
         "universityKeywords": { 
          "type": "string", 
          "index": "not_analyzed" 
         } 
         } 
        }, 
        "discussionTitle": { 
         "type": "string" 
        }, 
        "postDate": { 
         "type": "date", 
         "format": "strict_date_optional_time||epoch_millis" 
        }, 
        "postID": { 
         "type": "integer" 
        }, 
        "postText": { 
         "type": "string" 
        }, 
        "query": { 
         "properties": { 
         "match_all": { 
          "type": "object" 
         } 
         } 
        }, 
        "threadID": { 
         "type": "integer" 
        }, 
        "threadTitle": { 
         "type": "string" 
        } 
       } 
      } 
      } 
     } 
    } 
を投稿します

これは私がelasticsearch python clientでPythonの

processMap.put("Applications", new ArrayList<>(Arrays.asList("apply", "applied", "applicant", "applying", "application", "applications"))); 
     processMap.put("Offers", new ArrayList<>(Arrays.asList("offers", "offer", "offered", "offering"))); 
     processMap.put("Enrollment", new ArrayList<>(Arrays.asList("enrolling","enroled","enroll", "enrolment", "enrollment","enrol","enrolled"))); 
     processMap.put("Requirements", new ArrayList<>(Arrays.asList("requirement","requirements", "require"))); 
+0

[Python Elasticsearch Client](https://elasticsearch-py.readthedocs.io/ja/master/)? –

+0

焦がし澱粉?私はパッケージをインストールしましたが、このデータセットをどのようにしてPythonにするかを理解できません。小さな例が非常に便利です。 –

+0

"educationforumsenriched2":{ "マッピング":{ "渦":{ "プロパティ":{ "CourseInfo":これは私のelasticsearchインデックスのマッピング構造である{... –

答えて

1

に同じことをやりたい、私はJavaベースのプロセス情報タグを作成するために使用されるコード、あなたが成功した接続を確立したら、あなただけのDSLを提供する必要がありますクエリと、必要な情報を取得するために検索したいインデックス(たとえば、クエリ:

GET educationforumsenriched2/_search 
{ 
    "query": { 
     "match" : { 
      "CourseInfo.subjectKeywords" : "foo" 
     } 
    } 
} 

Pythonで同等では次のようになります。

from elasticsearch import Elasticsearch 

es = Elasticsearch({"host": "localhost", "port": 9200}) #many other settings are available if using https and so on 

query = { 
     "query": { 
      "match" : { 
       "CourseInfo.subjectKeywords" : "foo" 
      } 
     } 
    } 
res = es.search(index="educationforumsenriched2", body=query) 

#do some processing 

#create new document in ES 
es.create(index="educationforumsenriched2", body=new_doc_after_processing) 

編集:ちょうどそれについて考えるが、あなたの処理があまりにも複雑ではない場合もingest pipeline

の構築について考えることができ
+0

ありがとうございます。しかし、どのようにして結果をesのような構造にして、問題のようなフィールドの列を持つデータフレームのような構造にすることができますか? –

+0

@BAstu私たちはどんな種類のデータフレーム、pandasデータフレームですか?スパークのデータフレーム?たぶんこの質問は役に立ちます:https://stackoverflow.com/questions/25186148/creating-dataframe-from-elasticsearch-results – Adonis

+0

はいpandasデータフレーム。ありがとう –

関連する問題