1

The each searchRequest.toString() and each error info.

I think if you see the summary at bottom before check those search body and error, should be more easy to understand my problem.

SEARCH BODY

{
"from" : 0,
"size" : 12,
"query" : {
    "custom_filters_score" : {
        "query" : {
            "bool" : {
                "must" : {
                    "term" : {
                        "2474" : [ "20", "17" ]
                    }
                },
                "should" : {
                    "term" : {
                        "productName" : {
                            "value" : "xxx",
                            "boost" : 3.0
                        }
                    }
                }
            }
        },
        "filters" : [ {
            "filter" : {
                "terms" : {
                    "availableStock" : [ 0 ]
                }
            },
            "boost" : -10.0
        } ]
    }
},
"filter" : {
    "bool" : {
        "must_not" : {
            "term" : {
                "ecPrice" : -1
            }
        }
    }
},
"sort" : [ {
    "_score" : {
        "order" : "desc"
    }
} ],
"facets" : {
    "productBrandName" : {
        "terms" : {
            "field" : "productBrandName",
            "size" : 10
        }
    }
},
"highlight" : {
    "pre_tags" : [ "<font style='color:red'>" ],
    "post_tags" : [ "</font>" ],
    "fields" : {
        "productName" : { },
        "drugTreatment" : { }
    }
}

}

ERROR:

 QueryParsingException[[hy_index] [bool] query does not support [must]];

SEARCH BODY

{
"from" : 0,
"size" : 12,
"query" : {
    "custom_filters_score" : {
        "query" : {
            "bool" : {
                "should" : {
                    "term" : {
                        "2474" : [ "20", "17" ]
                    }
                }
            }
        },
        "filters" : [ ]
    }
},
"filter" : {
    "bool" : {
        "must_not" : {
            "term" : {
                "ecPrice" : -1
            }
        }
    }
},
"sort" : [ {
    "_score" : {
        "order" : "desc"
    }
} ],
"facets" : {
    "productBrandName" : {
        "terms" : {
            "field" : "productBrandName",
            "size" : 10
        }
    }
},
"highlight" : {
    "pre_tags" : [ "<font style='color:red'>" ],
    "post_tags" : [ "</font>" ],
    "fields" : {
        "productName" : { },
        "drugTreatment" : { }
    }
}

}

ERROR

QueryParsingException[[hy_index] [bool] query does not support [should]]

SEARCH BODY

{
"from" : 0,
"size" : 12,
"query" : {
    "custom_filters_score" : {
        "query" : {
            "bool" : {
                "should" : [ {
                    "term" : {
                        "productName" : {
                            "value" : "xxx",
                            "boost" : 3.0
                        }
                    }
                }, {
                    "term" : {
                        "2474" : [ "20", "17" ]
                    }
                } ]
            }
        },
        "filters" : [ {
            "filter" : {
                "terms" : {
                    "availableStock" : [ 0 ]
                }
            },
            "boost" : -10.0
        } ]
    }
},
"filter" : {
    "bool" : {
        "must_not" : {
            "term" : {
                "ecPrice" : -1
            }
        }
    }
},
"sort" : [ {
    "_score" : {
        "order" : "desc"
    }
} ],
"facets" : {
    "productBrandName" : {
        "terms" : {
            "field" : "productBrandName",
            "size" : 10
        }
    }
},
"highlight" : {
    "pre_tags" : [ "<font style='color:red'>" ],
    "post_tags" : [ "</font>" ],
    "fields" : {
        "productName" : { },
        "drugTreatment" : { }
    }
}

}

ERROR

QueryParsingException[[hy_index] [_na] query malformed, must start with start_object];

SEARCH BODY

{
"from" : 0,
"size" : 12,
"query" : {
    "custom_filters_score" : {
        "query" : {
            "bool" : {
                "should" : {
                    "term" : {
                        "productName" : {
                            "value" : "撒",
                            "boost" : 3.0
                        }
                    }
                }
            }
        },
        "filters" : [ {
            "filter" : {
                "terms" : {
                    "availableStock" : [ 0 ]
                }
            },
            "boost" : -10.0
        } ]
    }
},
"filter" : {
    "bool" : {
        "must_not" : {
            "term" : {
                "ecPrice" : -1
            }
        }
    }
},
"sort" : [ {
    "_score" : {
        "order" : "desc"
    }
} ],
"facets" : {
    "productBrandName" : {
        "terms" : {
            "field" : "productBrandName",
            "size" : 10
        }
    }
},
"highlight" : {
    "pre_tags" : [ "<font style='color:red'>" ],
    "post_tags" : [ "</font>" ],
    "fields" : {
        "productName" : { },
        "drugTreatment" : { }
    }
}

}

This one has no error.

Now, Summary.

No matter I use should or must at "term" : {"2474" : [ "20", "17" ]}.

It always get error when I set "term" : {"2474" : [ "20", "17" ]} in query body.

Once I remove "term" : {"2474" : [ "20", "17" ]} from query body, it works fine.

Why?

3
  • +1 for your clear question ..! Commented May 13, 2014 at 2:36
  • @BlackPOP guess i am stupid, that day i got this error by using QueryBuilders.termQuery(String name, String...values). but after you asid it should be terms instead term, i just can't find the method termQuery with parameters String name, String...values, just String name, String value... Commented May 13, 2014 at 4:25
  • You almost found the answer..! It happens...Cheers..! Commented May 13, 2014 at 4:35

1 Answer 1

1

Term query expect only one value. Terms mean more than one value.. Try lik this

 "terms" : {"2474" : [ "20", "17" ]}

Change term query to terms.. Refer following url ,http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.