search not working as expected
sajadghawami opened this issue · comments
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