Javascript Querying on Elasticsearch does not work on Child Elements












1















I am trying to display searchresults on a elasticsearch database in my reactjs-app. Nevertheless I can only access the upper layer of key value pairs and am unable to reach the children.



The structure of my elasticsearch-objects is as follows:



...
"hits":[{
"_index":"knowledgecrawler",
"_type":"doc",
"_id":"5fea73f38399f4c01f",
"_score":1.0,
"_source":{
"content":"content comes here",
"meta":{
"author":"Jones@stackoverflow.com",
"title":"I am lost"
"date":"today",
"keywords":["Stackoverflow"],
"language":"Javascript",
}
"raw":{
"date":"2017-03-08",
"subject":"How do I get here?"
}
}}]


The elasticsearch-object is much bigger, but I am only searching in the "hits". With the following lines of code i can easily display the firstlevel values(_index, _type, _id), but any attempt to access the children failed so far:



render() {
const result = this.props.result;
return (
<div className={this.props.bemBlocks.item().mix(this.props.bemBlocks.container("item"))} key={result._id}>
<div className={this.props.bemBlocks.item("title")}>{result._id}</div>
<div className={this.props.bemBlocks.item("title")}>{result._type}</div>
</div>
)
}


Can anybody advice me how to access the children of _source. E.g. I want to display the author in my frontend.



EDIT:



So the error is apparently due to the fact that the _source field in Elasticsearch is not indexed and thus not searchable (according to the elasticsearch docs).
I haven't come up with a solution so far, but will post it here, when I find it. Help is also much appreciated.










share|improve this question





























    1















    I am trying to display searchresults on a elasticsearch database in my reactjs-app. Nevertheless I can only access the upper layer of key value pairs and am unable to reach the children.



    The structure of my elasticsearch-objects is as follows:



    ...
    "hits":[{
    "_index":"knowledgecrawler",
    "_type":"doc",
    "_id":"5fea73f38399f4c01f",
    "_score":1.0,
    "_source":{
    "content":"content comes here",
    "meta":{
    "author":"Jones@stackoverflow.com",
    "title":"I am lost"
    "date":"today",
    "keywords":["Stackoverflow"],
    "language":"Javascript",
    }
    "raw":{
    "date":"2017-03-08",
    "subject":"How do I get here?"
    }
    }}]


    The elasticsearch-object is much bigger, but I am only searching in the "hits". With the following lines of code i can easily display the firstlevel values(_index, _type, _id), but any attempt to access the children failed so far:



    render() {
    const result = this.props.result;
    return (
    <div className={this.props.bemBlocks.item().mix(this.props.bemBlocks.container("item"))} key={result._id}>
    <div className={this.props.bemBlocks.item("title")}>{result._id}</div>
    <div className={this.props.bemBlocks.item("title")}>{result._type}</div>
    </div>
    )
    }


    Can anybody advice me how to access the children of _source. E.g. I want to display the author in my frontend.



    EDIT:



    So the error is apparently due to the fact that the _source field in Elasticsearch is not indexed and thus not searchable (according to the elasticsearch docs).
    I haven't come up with a solution so far, but will post it here, when I find it. Help is also much appreciated.










    share|improve this question



























      1












      1








      1








      I am trying to display searchresults on a elasticsearch database in my reactjs-app. Nevertheless I can only access the upper layer of key value pairs and am unable to reach the children.



      The structure of my elasticsearch-objects is as follows:



      ...
      "hits":[{
      "_index":"knowledgecrawler",
      "_type":"doc",
      "_id":"5fea73f38399f4c01f",
      "_score":1.0,
      "_source":{
      "content":"content comes here",
      "meta":{
      "author":"Jones@stackoverflow.com",
      "title":"I am lost"
      "date":"today",
      "keywords":["Stackoverflow"],
      "language":"Javascript",
      }
      "raw":{
      "date":"2017-03-08",
      "subject":"How do I get here?"
      }
      }}]


      The elasticsearch-object is much bigger, but I am only searching in the "hits". With the following lines of code i can easily display the firstlevel values(_index, _type, _id), but any attempt to access the children failed so far:



      render() {
      const result = this.props.result;
      return (
      <div className={this.props.bemBlocks.item().mix(this.props.bemBlocks.container("item"))} key={result._id}>
      <div className={this.props.bemBlocks.item("title")}>{result._id}</div>
      <div className={this.props.bemBlocks.item("title")}>{result._type}</div>
      </div>
      )
      }


      Can anybody advice me how to access the children of _source. E.g. I want to display the author in my frontend.



      EDIT:



      So the error is apparently due to the fact that the _source field in Elasticsearch is not indexed and thus not searchable (according to the elasticsearch docs).
      I haven't come up with a solution so far, but will post it here, when I find it. Help is also much appreciated.










      share|improve this question
















      I am trying to display searchresults on a elasticsearch database in my reactjs-app. Nevertheless I can only access the upper layer of key value pairs and am unable to reach the children.



      The structure of my elasticsearch-objects is as follows:



      ...
      "hits":[{
      "_index":"knowledgecrawler",
      "_type":"doc",
      "_id":"5fea73f38399f4c01f",
      "_score":1.0,
      "_source":{
      "content":"content comes here",
      "meta":{
      "author":"Jones@stackoverflow.com",
      "title":"I am lost"
      "date":"today",
      "keywords":["Stackoverflow"],
      "language":"Javascript",
      }
      "raw":{
      "date":"2017-03-08",
      "subject":"How do I get here?"
      }
      }}]


      The elasticsearch-object is much bigger, but I am only searching in the "hits". With the following lines of code i can easily display the firstlevel values(_index, _type, _id), but any attempt to access the children failed so far:



      render() {
      const result = this.props.result;
      return (
      <div className={this.props.bemBlocks.item().mix(this.props.bemBlocks.container("item"))} key={result._id}>
      <div className={this.props.bemBlocks.item("title")}>{result._id}</div>
      <div className={this.props.bemBlocks.item("title")}>{result._type}</div>
      </div>
      )
      }


      Can anybody advice me how to access the children of _source. E.g. I want to display the author in my frontend.



      EDIT:



      So the error is apparently due to the fact that the _source field in Elasticsearch is not indexed and thus not searchable (according to the elasticsearch docs).
      I haven't come up with a solution so far, but will post it here, when I find it. Help is also much appreciated.







      javascript reactjs elasticsearch children querying






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 8:18







      Jones1220

















      asked Nov 22 '18 at 13:20









      Jones1220Jones1220

      6661218




      6661218
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Let's say you have following data:



          data = {"hits":[{
          "_index":"knowledgecrawler",
          "_type":"doc",
          "_id":"5fea73f38399f4c01f",
          "_score":1.0,
          "_source":{
          "content":"content comes here",
          "meta":{
          "author":"Jones@stackoverflow.com",
          "title":"I am lost"
          "date":"today",
          "keywords":["Stackoverflow"],
          "language":"Javascript",
          }
          "raw":{
          "date":"2017-03-08",
          "subject":"How do I get here?"
          }
          }}]}


          Now you question is : Can anybody advice me how to access the children of _source. E.g. I want to display the author in my frontend.



          So, you can do the following to get the author of _source:



          {data.hits && data.hits.length > 0 && data.hits[0]._source && data.hits[0]._source.meta && data.hits[0]._source.meta.author ?data.hits[0]._source.meta.author : ''}


          If you have multiple hits, then you can use array.map() like this:



          data.hits.map(value => value._source && value._source.meta && value._source.meta.author ? value._source.meta.author : '')





          share|improve this answer


























          • This seems logical to me, but for some reason it does not work in my case...

            – Jones1220
            Nov 22 '18 at 13:34











          • @Jones1220 Are you getting errors?

            – Triyugi Narayan Mani
            Nov 22 '18 at 13:34











          • No errors. But my frontend does not display the values (This works when I stay on the top level)

            – Jones1220
            Nov 22 '18 at 13:35











          • Ok sorry. It throws the following error: TypeError: "result._source.meta is undefined" where result is the data.hits object.

            – Jones1220
            Nov 22 '18 at 13:37











          • Then you need to check if result._source.meta is not undefined and then print it.

            – Triyugi Narayan Mani
            Nov 22 '18 at 13:38











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431926%2fjavascript-querying-on-elasticsearch-does-not-work-on-child-elements%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Let's say you have following data:



          data = {"hits":[{
          "_index":"knowledgecrawler",
          "_type":"doc",
          "_id":"5fea73f38399f4c01f",
          "_score":1.0,
          "_source":{
          "content":"content comes here",
          "meta":{
          "author":"Jones@stackoverflow.com",
          "title":"I am lost"
          "date":"today",
          "keywords":["Stackoverflow"],
          "language":"Javascript",
          }
          "raw":{
          "date":"2017-03-08",
          "subject":"How do I get here?"
          }
          }}]}


          Now you question is : Can anybody advice me how to access the children of _source. E.g. I want to display the author in my frontend.



          So, you can do the following to get the author of _source:



          {data.hits && data.hits.length > 0 && data.hits[0]._source && data.hits[0]._source.meta && data.hits[0]._source.meta.author ?data.hits[0]._source.meta.author : ''}


          If you have multiple hits, then you can use array.map() like this:



          data.hits.map(value => value._source && value._source.meta && value._source.meta.author ? value._source.meta.author : '')





          share|improve this answer


























          • This seems logical to me, but for some reason it does not work in my case...

            – Jones1220
            Nov 22 '18 at 13:34











          • @Jones1220 Are you getting errors?

            – Triyugi Narayan Mani
            Nov 22 '18 at 13:34











          • No errors. But my frontend does not display the values (This works when I stay on the top level)

            – Jones1220
            Nov 22 '18 at 13:35











          • Ok sorry. It throws the following error: TypeError: "result._source.meta is undefined" where result is the data.hits object.

            – Jones1220
            Nov 22 '18 at 13:37











          • Then you need to check if result._source.meta is not undefined and then print it.

            – Triyugi Narayan Mani
            Nov 22 '18 at 13:38
















          1














          Let's say you have following data:



          data = {"hits":[{
          "_index":"knowledgecrawler",
          "_type":"doc",
          "_id":"5fea73f38399f4c01f",
          "_score":1.0,
          "_source":{
          "content":"content comes here",
          "meta":{
          "author":"Jones@stackoverflow.com",
          "title":"I am lost"
          "date":"today",
          "keywords":["Stackoverflow"],
          "language":"Javascript",
          }
          "raw":{
          "date":"2017-03-08",
          "subject":"How do I get here?"
          }
          }}]}


          Now you question is : Can anybody advice me how to access the children of _source. E.g. I want to display the author in my frontend.



          So, you can do the following to get the author of _source:



          {data.hits && data.hits.length > 0 && data.hits[0]._source && data.hits[0]._source.meta && data.hits[0]._source.meta.author ?data.hits[0]._source.meta.author : ''}


          If you have multiple hits, then you can use array.map() like this:



          data.hits.map(value => value._source && value._source.meta && value._source.meta.author ? value._source.meta.author : '')





          share|improve this answer


























          • This seems logical to me, but for some reason it does not work in my case...

            – Jones1220
            Nov 22 '18 at 13:34











          • @Jones1220 Are you getting errors?

            – Triyugi Narayan Mani
            Nov 22 '18 at 13:34











          • No errors. But my frontend does not display the values (This works when I stay on the top level)

            – Jones1220
            Nov 22 '18 at 13:35











          • Ok sorry. It throws the following error: TypeError: "result._source.meta is undefined" where result is the data.hits object.

            – Jones1220
            Nov 22 '18 at 13:37











          • Then you need to check if result._source.meta is not undefined and then print it.

            – Triyugi Narayan Mani
            Nov 22 '18 at 13:38














          1












          1








          1







          Let's say you have following data:



          data = {"hits":[{
          "_index":"knowledgecrawler",
          "_type":"doc",
          "_id":"5fea73f38399f4c01f",
          "_score":1.0,
          "_source":{
          "content":"content comes here",
          "meta":{
          "author":"Jones@stackoverflow.com",
          "title":"I am lost"
          "date":"today",
          "keywords":["Stackoverflow"],
          "language":"Javascript",
          }
          "raw":{
          "date":"2017-03-08",
          "subject":"How do I get here?"
          }
          }}]}


          Now you question is : Can anybody advice me how to access the children of _source. E.g. I want to display the author in my frontend.



          So, you can do the following to get the author of _source:



          {data.hits && data.hits.length > 0 && data.hits[0]._source && data.hits[0]._source.meta && data.hits[0]._source.meta.author ?data.hits[0]._source.meta.author : ''}


          If you have multiple hits, then you can use array.map() like this:



          data.hits.map(value => value._source && value._source.meta && value._source.meta.author ? value._source.meta.author : '')





          share|improve this answer















          Let's say you have following data:



          data = {"hits":[{
          "_index":"knowledgecrawler",
          "_type":"doc",
          "_id":"5fea73f38399f4c01f",
          "_score":1.0,
          "_source":{
          "content":"content comes here",
          "meta":{
          "author":"Jones@stackoverflow.com",
          "title":"I am lost"
          "date":"today",
          "keywords":["Stackoverflow"],
          "language":"Javascript",
          }
          "raw":{
          "date":"2017-03-08",
          "subject":"How do I get here?"
          }
          }}]}


          Now you question is : Can anybody advice me how to access the children of _source. E.g. I want to display the author in my frontend.



          So, you can do the following to get the author of _source:



          {data.hits && data.hits.length > 0 && data.hits[0]._source && data.hits[0]._source.meta && data.hits[0]._source.meta.author ?data.hits[0]._source.meta.author : ''}


          If you have multiple hits, then you can use array.map() like this:



          data.hits.map(value => value._source && value._source.meta && value._source.meta.author ? value._source.meta.author : '')






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 '18 at 13:42

























          answered Nov 22 '18 at 13:30









          Triyugi Narayan ManiTriyugi Narayan Mani

          1,03141527




          1,03141527













          • This seems logical to me, but for some reason it does not work in my case...

            – Jones1220
            Nov 22 '18 at 13:34











          • @Jones1220 Are you getting errors?

            – Triyugi Narayan Mani
            Nov 22 '18 at 13:34











          • No errors. But my frontend does not display the values (This works when I stay on the top level)

            – Jones1220
            Nov 22 '18 at 13:35











          • Ok sorry. It throws the following error: TypeError: "result._source.meta is undefined" where result is the data.hits object.

            – Jones1220
            Nov 22 '18 at 13:37











          • Then you need to check if result._source.meta is not undefined and then print it.

            – Triyugi Narayan Mani
            Nov 22 '18 at 13:38



















          • This seems logical to me, but for some reason it does not work in my case...

            – Jones1220
            Nov 22 '18 at 13:34











          • @Jones1220 Are you getting errors?

            – Triyugi Narayan Mani
            Nov 22 '18 at 13:34











          • No errors. But my frontend does not display the values (This works when I stay on the top level)

            – Jones1220
            Nov 22 '18 at 13:35











          • Ok sorry. It throws the following error: TypeError: "result._source.meta is undefined" where result is the data.hits object.

            – Jones1220
            Nov 22 '18 at 13:37











          • Then you need to check if result._source.meta is not undefined and then print it.

            – Triyugi Narayan Mani
            Nov 22 '18 at 13:38

















          This seems logical to me, but for some reason it does not work in my case...

          – Jones1220
          Nov 22 '18 at 13:34





          This seems logical to me, but for some reason it does not work in my case...

          – Jones1220
          Nov 22 '18 at 13:34













          @Jones1220 Are you getting errors?

          – Triyugi Narayan Mani
          Nov 22 '18 at 13:34





          @Jones1220 Are you getting errors?

          – Triyugi Narayan Mani
          Nov 22 '18 at 13:34













          No errors. But my frontend does not display the values (This works when I stay on the top level)

          – Jones1220
          Nov 22 '18 at 13:35





          No errors. But my frontend does not display the values (This works when I stay on the top level)

          – Jones1220
          Nov 22 '18 at 13:35













          Ok sorry. It throws the following error: TypeError: "result._source.meta is undefined" where result is the data.hits object.

          – Jones1220
          Nov 22 '18 at 13:37





          Ok sorry. It throws the following error: TypeError: "result._source.meta is undefined" where result is the data.hits object.

          – Jones1220
          Nov 22 '18 at 13:37













          Then you need to check if result._source.meta is not undefined and then print it.

          – Triyugi Narayan Mani
          Nov 22 '18 at 13:38





          Then you need to check if result._source.meta is not undefined and then print it.

          – Triyugi Narayan Mani
          Nov 22 '18 at 13:38


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431926%2fjavascript-querying-on-elasticsearch-does-not-work-on-child-elements%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Create new schema in PostgreSQL using DBeaver

          Deepest pit of an array with Javascript: test on Codility

          Costa Masnaga