Java ElasticSearch查询和或
这是我的地图Java ElasticSearch查询和或,java,
elasticsearch,nosql,Java,
elasticsearch,Nosql,这是我的地图 { "app" : { "mappings" : { "patient" : { "properties" : { "LastName" : { "type" : "string" }, "consultations" : { "type" : "nested", "properties" : {
{
"app" : {
"mappings" : {
"patient" : {
"properties" : {
"LastName" : {
"type" : "string"
},
"consultations" : {
"type" : "nested",
"properties" : {
"deleted" : {
"type" : "boolean"
},
"diagnosis" : {
"type" : "string"
},
"documentDate" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"firstName" : {
"type" : "string"
},
"lastName" : {
"type" : "string"
},
"middleName" : {
"type" : "string"
},
"prescriptions" : {
"type" : "string"
}
}
},
"firstName" : {
"type" : "string"
},
"gender" : {
"type" : "string"
},
"id" : {
"type" : "string",
"index" : "not_analyzed"
},
"lastName" : {
"type" : "string"
},
"middleName" : {
"type" : "string"
},
"owner" : {
"type" : "string",
"index" : "not_analyzed"
},
"patientPin" : {
"type" : "string"
}
}
}
}
}
}
Then let's say I have this data
{
"id":"21",
"firstName":"Scrappy",
"patientPin":"2012010000000021",
"middleName":"D",
"consultations":[
{
"id":null,
"prescriptions":[
"GADOTERIC Acid DOTAREM"
],
"diagnosis":[
"Kawasaki's Disease",
"Alcohol Intoxication"
],
"documentDate":"2014-07-31T13:19:00.000+08:00",
"deleted":false,
"lastName":"Doo",
"firstName":"Scrappy",
"middleName":"D"
}
],
"owner":"TENANT1",
"gender":"FEMALE",
"lastName":"Doo"
}
{
"id":"100066",
"firstName":"Kyel ",
"patientPin":"201408000001",
"middleName":"John ",
"consultations":[
{
"id":null,
"prescriptions":[
],
"diagnosis":[
"headache"
],
"documentDate":"2014-08-05T10:10:00.000+08:00",
"deleted":false,
"lastName":"David",
"firstName":"Mika",
"middleName":"John "
}
],
"owner":"TENANT1",
"gender":"MALE",
"lastName":"David"
}
如何查询咨询过头痛或酒精中毒的患者?对于您的结果,我建议您使用过滤器 你可以使用 对于或,术语筛选器将文档与提供的任何值匹配,这意味着不使用或用于值
client.prepareSearch("app").setTypes("patient").setPostFilter(
FilterBuilders.termsFilter("consultations.diagnosis","headache","Alcohol Intoxication")
);
对于和
client.prepareSearch("app").setTypes("patient").setPostFilter(
FilterBuilders.andFilter(
FilterBuilders.termsFilter("consultations.diagnosis","headache"),
FilterBuilders.termsFilter("consultations.diagnosis","Alcohol Intoxication")
)
);
为此,要筛选的任何值都应该是index:not_-analysis。
尝试学习 你需要完整的Java应用程序吗?如果你能提供Java客户机查询等价物,请做soI我正在尝试我只是不知道怎么做。为什么它是必须的?而不是应该?这不是一个OR操作符吗?我也在尝试构建一个动态查询。另外,如果我想寻找头痛和酒精中毒的咨询,该怎么办?在上面的问题中,termsQuery不匹配头痛或酒精中毒,必须确保至少应该这样做。我明白了,但若我想寻求头痛和酒精中毒的咨询,那个该怎么办?对于您给出的现有查询,我该如何处理?我已经尝试了这两种方法,但它们似乎都不起作用。我正在查询嵌套类型。