Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search not working as expected #103

Open
sajadghawami opened this issue May 6, 2020 · 0 comments
Open

search not working as expected #103

sajadghawami opened this issue May 6, 2020 · 0 comments

Comments

@sajadghawami
Copy link

sajadghawami commented May 6, 2020

hey there,

i am currently having issues with the search.

This is the code:

sellerProductSchema.plugin(mongoosastic, {
  esClient,
  index: 'sellerproduct',
  transform: (data: any, post: any) => {
    const transformedData = { ...data, seller: data.seller._id };
    return transformedData;
  },
});


const ElasticSearchSellerProductTC = composeWithElastic({
  graphqlTypeName: 'sellerProduct',
  elasticIndex: 'sellerproduct',
  elasticType: 'sellerproduct',
  elasticMapping: {
    properties: {
      title: {
        type: 'keyword',
      },
      category: {
        type: 'keyword',
      },
      price: { type: 'long' },
      shortDescription: {
        type: 'text',
      },
      longDescription: {
        type: 'text',
      },
      seller: {
        type: 'keyword',
      },
      image: { type: 'text' },
      updatedAt: { type: 'date' },
      createdAt: { type: 'date' },
    },
  },
  elasticClient: esClient,
});



sellerProductSchemaComposer.Query.addFields({
  elasticSearchSellerProduct: ElasticSearchSellerProductTC.getResolver('search'),
  //
  elastic50: elasticApiFieldConfig({
    host: 'elasticsearch:9200',
    apiVersion: '5.6',
    log: 'trace',
  }),
});

The following query does not work:

query {
  elasticSearchSellerProduct(
    query: { simple_query_string: { query: "title", fields: ["title"] } }
  ) { 
    hits {
      fields
      _id
      _source {
        title
      }
    }
  }
}

Reponse:

{
  "data": {
    "elasticSearchSellerProduct": {
      "hits": []
    }
  }
}

This is the corresponding log-trace for the above request:

node_1           | Elasticsearch TRACE: 2020-05-06T12:46:13Z
node_1           |   -> POST http://elasticsearch:9200/sellerproduct/_search?type=sellerproduct
node_1           |   {
node_1           |     "_source": [
node_1           |       "title"
node_1           |     ],
node_1           |     "query": {
node_1           |       "simple_query_string": {
node_1           |         "query": "title",
node_1           |         "fields": [
node_1           |           "title"
node_1           |         ]
node_1           |       }
node_1           |     }
node_1           |   }
node_1           |   <- 200
node_1           |   {
node_1           |     "took": 2,
node_1           |     "timed_out": false,
node_1           |     "_shards": {
node_1           |       "total": 1,
node_1           |       "successful": 1,
node_1           |       "skipped": 0,
node_1           |       "failed": 0
node_1           |     },
node_1           |     "hits": {
node_1           |       "total": {
node_1           |         "value": 0,
node_1           |         "relation": "eq"
node_1           |       },
node_1           |       "max_score": null,
node_1           |       "hits": []
node_1           |     }
node_1           |   }
node_1           |

But this query does work, and gives the right details:

query {
  elastic50 {
    search(q: "title")
  }
}

Whats interesting though is that for the query with elastic50 i dont have autocompletion in graphiql - really odd...

Whats happening here? Any help would be much appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant