我正在尝试将MYSQL查询转换为Elasticsearch。该查询包括在不同字段上的多个条件。让我解释一下我要达到的目标。我的MySQL查询是
Select * from data_fl where city IN 'miami,miamibeach,etc' AND phone!=0 AND (name like '%abc%' OR address like '%abc%' OR zip_code like '%abc%' OR phone Like '%abc')
如何在Elasticsearch中复制此查询。我的尝试是
$params = [
'index'=>'us_data_'.strtolower($state_code),
'body' => [
'query' => [
'bool'=>[
'filter'=>[
'term'=>['city_code'=>$city_name]
],
'should' => [
'query_string'=>[
'query'=>"*".$service."*",
'fields'=>['name','contact_no','zip_code','city_code'],
]
]
]
]
]
];
但这不会返回任何内容。我正在使用Elasticsearch 7.6并尝试在Kibana上使用curl复制此查询,但答案仍然相同。
期待帮助
根据要求,索引的映射是
{
"mapping": {
"_doc": {
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"address": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"city_code": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"contact_no": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"date_added": {
"type": "date"
},
"date_updated": {
"type": "date"
},
"featured": {
"type": "long"
},
"id": {
"type": "long"
},
"location_id": {
"type": "long"
},
"main_cate": {
"type": "long"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"slug": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"source": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"state_code": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"status": {
"type": "long"
},
"zip_code": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
我接受的文件是
"hits" : {
"total" : {
"value" : 10000,
"relation" : "gte"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "us_data_al",
"_type" : "_doc",
"_id" : "8kmR1HABkLcaz3xayZOg",
"_score" : 1.0,
"_source" : {
"promotion" : null,
"image" : null,
"name" : "Port City Realty",
"city_code" : "Mobile",
"services" : null,
"promotion_exp_date" : null,
"tuesdayopen" : null,
"tuesdayclose" : null,
"wednesdayopen" : null,
"thursdayclose" : null,
"@timestamp" : "2020-03-13T15:44:45.330Z",
"date_updated" : "2020-03-06T00:00:00.000Z",
"mondayopen" : null,
"contact_no" : "2516891228",
"id" : 1941,
"fridayclose" : null,
"featured" : 0,
"main_cate" : 1,
"wednesdayclose" : null,
"sundayopen" : null,
"state_code" : "AL",
"video" : null,
"address" : "4826 Whispering Oaks Lane",
"user_id" : null,
"slug" : "2516891228-port-city-realty-mobile-al-36695",
"timezone" : null,
"source" : "USA Business",
"description" : null,
"fridayopen" : null,
"price" : null,
"saturdayopen" : null,
"saturdayclose" : null,
"date_added" : "2020-03-05T19:00:00.000Z",
"thursdayopen" : null,
"@version" : "1",
"status" : 1,
"mondayclose" : null,
"zip_code" : "36695",
"private_contact" : null,
"location_id" : 0,
"sundayclose" : null
}
}
您正在使事情变得复杂,并试图在Elasticsearch中适应MySQL概念。在这种情况下,您需要正确定义索引映射(根据搜索要求来字段数据类型及其分析器),并相应地构建查询。
我已经获取了您的示例,并且没有更改索引映射和示例文档,但是更改了搜索查询以显示如何处理现有数据和需求(可能无法在所有情况下都有效,但是您有所了解)搜索。
{
"query": {
"multi_match": { --> note and read about multi_match query
"query": "36695",
"fields": [
"address",
"city_code", --> add more fields if you need to be
"zip_code",
"contact_no"
]
}
}
}
搜索结果将带您的示例文档:
"hits": [
{
"_index": "so_mysql_dsl",
"_type": "_doc",
"_id": "1",
"_score": 0.2876821,
"_source": {
"promotion": null,
"image": null,
"name": "Port City Realty",
"city_code": "Mobile",
"services": null,
"promotion_exp_date": null,
"tuesdayopen": null,
"tuesdayclose": null,
"wednesdayopen": null,
"thursdayclose": null,
"@timestamp": "2020-03-13T15:44:45.330Z",
"date_updated": "2020-03-06T00:00:00.000Z",
"mondayopen": null,
"contact_no": "2516891228",
"id": 1941,
"fridayclose": null,
"featured": 0,
"main_cate": 1,
"wednesdayclose": null,
"sundayopen": null,
"state_code": "AL",
"video": null,
"address": "4826 Whispering Oaks Lane",
"user_id": null,
"slug": "2516891228-port-city-realty-mobile-al-36695",
"timezone": null,
"source": "USA Business",
"description": null,
"fridayopen": null,
"price": null,
"saturdayopen": null,
"saturdayclose": null,
"date_added": "2020-03-05T19:00:00.000Z",
"thursdayopen": null,
"@version": "1",
"status": 1,
"mondayclose": null,
"zip_code": "36695",
"private_contact": null,
"location_id": 0,
"sundayclose": null
}
}
]
我应该如何将这个MySQL查询转换为HQL来检索我需要的一些数据? 在我的代码中,有POJO ProcessedUrl,它映射了id/url/date/set(句子)字段。我想做一些类似的事情: 然后遍历此结果,为每个URL打印&。 我知道我的查询应该返回中的字段,那么我如何返回一些分组查询并从中检索不直接保存在表中的数据呢?就像每个URL的一样? 多谢帮忙。
我试图将我的Mysql查询转换为JPQL,但我不知道哪个工具可以在eclipse上使用而无需编译。 我的日志没有告诉我哪里是错误,所以我找不到哪里是错误的语法。 谢谢你的帮助!
前面我们介绍了如何使用 SELECT、INSERT、UPDATE 和 DELETE 语句对 MySQL 进行简单访问和操作。下面在此基础上开始学习子查询。 子查询是 MySQL 中比较常用的查询方法,通过子查询可以实现多表查询。 子查询指将一个查询语句嵌套在另一个查询语句中。子查询可以在 SELECT、UPDATE 和 DELETE 语句中使用,而且可以进行多层嵌套。在实际开发时,子查询经常出现在
问题内容: 我将使用Sencha Touch将Android-Travellog应用程序移植到其他Plattforms。问题是,Sencha仅具有一个存储系统来存储数据,而似乎没有可能正确地进行MySql查询。而且,由于我以前的应用程序中的大多数Mysql代码已经存在,因此使用Senchas new System重做所有内容时,id会很痛苦。是否可以在Sencha中使用mysql(或任何其他sql
问题内容: 我在MySQL的ExtractValue函数方面有点问题。 这是我的示例XML: 这是我当前的查询: 结果如下: 这是我想要的: 有人可以帮我实现这一点..谢谢。 问题答案: 在这里回答了这个问题: 在MySQL中解析XML字符串 如果将子级更改为“ B”,则该文章中的解决方案应该起作用:
我如何写问题。*在jooq中而不是指定所有实体vaiables