Cannot reproduce a POST search query
See original GitHub issueHi,
I have searched for this into the issues before opening this one, but I cannot see a similar case. I want to perform a search query.
- Index: clients
- doc type: client
- Path: /clients/client/_search
- Method: POST
- Body:
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "del*",
"fields": [
"firstName",
"lastName"
]
}
},
{
"match": {
"merchantId": "44UudEcyFMbpLOGzG2HWpfngJ8o2"
}
}
]
}
}
}
Doing this with curl:
curl -X POST "https://xyz/clients/client/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "ale*",
"fields": [
"firstName",
"lastName"
]
}
},
{
"match": {
"merchantId": "44UudEcyFMbpLOGzG2HWpfngJ8o2"
}
}
]
}
}
}
'
Gives me 2 hits (correct!).
Same with POSTMAN (as attached) .
Now, the problem.
Here’s my code:
return client.search({
index: 'clients',
type: 'client',
body: {
query: {
bool: {
must: [
{
query_string: {
query: "ale*",
fields: ["firstName", "lastName"]
}
},
{
match: {
'merchantId': merchantId // Defined and logged <-
}
}
]
}
}
}
}
);
The result is empty, the log gives me this:
starting request {
"method": "POST",
"path": "/clients/client/_search",
"body": {
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "ale*",
"fields": [
"firstName",
"lastName"
]
}
},
{
"match": {
"merchantId": "44UudEcyFMbpLOGzG2HWpfngJ8o2"
}
}
]
}
}
},
"query": { }
}
info: Elasticsearch DEBUG: 2018-09-21T14:16:07Z
Request complete
info: ->! { took: 1,
timed_out: false,
_shards: { total: 1, successful: 1, skipped: 0, failed: 0 },
hits: { total: 0, max_score: null, hits: [] } }
What am I missing?
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
POST or GET in a search form? - Stack Overflow
The essence of the problem, is that a GET has no request body, and for that reason it cannot handle more complex request....
Read more >POST search engine - Vivaldi Forum
I have tried this like 8 times now, in Stable, Snapshot and in an internal build, and I cannot reproduce it. For me,...
Read more >Influencing your title links in search results - Google Developers
A title link is the title of a search result on Google Search and other properties (for example, Google News) that links to...
Read more >Google Chrome Privacy Whitepaper
Chrome prefetching - can be initiated by Chrome itself whenever it detects a search query typed in the omnibox, a likely beginning of...
Read more >Why would one employ a POST-based search engine on their ...
However, I'm working with an internal site search engine that receives and returns SERP requests POST-style. Why would it be designed to do...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am not creating the data, the data is there from days. Anyway, “brutally” executing your code works just fine, so definitely is something I have to figure out in my custom code. Thanks again for your support ( I close by myself 😃 )!
I created this simple example where I get back all the data.
I was asking if you are running the request just after the indexing operation because Elasticsearch is a near real-time engine. This means that the indexed data cannot be available instantaneously, but there is a time span where is not available. By default, that time span is 1 second, so if you run two requests against your express server:
And there is less than one second between the requests you will not find the data.
That’s why there is a
sleep
function in my code, and if you remove it, or you change the timeout at 200ms, you will not find anything.If you want to know more, or how to change the index refresh time, I suggest you read this fantastic document 😃