Problem with checking values of JSON array using Rest Assured - java

I'm trying to add some tests with Rest-Assured to my application, but I can't figure out how to assert some nested values. The error message is :
Expected: (a collection containing "json")
Actual: [[json, spring, gulp, path etc...]]
Here is the code :
when().
get("/api/personsByID/{id}/{count}", 262, 2).
then().
statusCode(200).
body("personDependencies.name", hasItems("json"));
And here is the JSON file that is returned by rest controller:
[
{
"id": 346,
"verified": true,
"displayName": "eda656a2c3cb59ae840e40a28ba4ab50bfb9de0185abcb901c6af6dc59d6668f",
"emails": [
{
"email": "16a23f2e5477df0bbcad718c3abc235b2cb8a1b6648d14f58d42a7be13df2b6e"
}
],
"personDependencies": [
{
"name": "json"
},
{
"name": "spring"
},
{
"name": "gulp"
},
{
"name": "path"
},
{
"name": "junit"
},
{
"name": "activemq"
},
{
"name": "hibernate"
},
{
"name": "jstl"
},
{
"name": "phantomjs"
},
{
"name": "activiti"
},
{
"name": "commons"
},
{
"name": "h2"
},
{
"name": "joda"
},
{
"name": "log4j"
},
{
"name": "exec"
},
{
"name": "admin"
},
{
"name": "coveralls"
},
{
"name": "cxf"
},
{
"name": "cglib"
},
{
"name": "camel"
},
{
"name": "sugaronrest"
},
{
"name": "tslint"
},
{
"name": "httpclient"
},
{
"name": "guava"
},
{
"name": "inventory"
},
{
"name": "jackson"
},
{
"name": "gson"
},
{
"name": "event"
},
{
"name": "OTRS"
},
{
"name": "maven"
},
{
"name": "karma"
},
{
"name": "slf4j"
},
{
"name": "postgresql"
},
{
"name": "typescript"
},
{
"name": "jasmine"
},
{
"name": "spa"
},
{
"name": "javax.servlet"
}
],
"countries": [],
"member_of": [],
"projects": [],
"employee_type": [],
"languages": [
{
"language": "reStructuredText",
"sum": 575
},
{
"language": "JSON",
"sum": 21
},
{
"language": "JavaScript",
"sum": 4467
},
{
"language": "Java",
"sum": 7958
},
{
"language": "Python",
"sum": 2
},
{
"language": "XML",
"sum": 477
},
{
"language": "Plain Text",
"sum": 41
}
],
"distance": 0.6028837702084446
}
]
I have no idea how to make proper assertions, any help would be great. Thanks!

If I am reading your question right you need to check if a certain values are present in a list that is returned for a particular ID
The below should work for you
given().when().get().then().body("find {it.id == 346}.personDependencies.name", hasItems("json", "jackson"));

The first problem you don't need to check the presence of an item with hasItems, you should use hasItem
when().
get("/api/personsByID/{id}/{count}", 262, 2).
then().
statusCode(200).
body("personDependencies.name", hasItem("json"));
Then if you need to add more message to the assertion when the test fails you can do such way:
when().
get("/api/personsByID/{id}/{count}", 262, 2).
then().
statusCode(200).
body("personDependencies.name", describedAs("Array not containing the provided item",hasItem("json")));
In your case you can validate such a way:
when().
get("/api/personsByID/{id}/{count}", 262, 2).
then().
statusCode(200).
body("personDependencies[*].name", hasItem("json"));

Related

Keycloak -18.0.1 issue with authorization and multiple polices/permissions

we are getting issue with multiple policies/permission.
Policy A - user A with scope A,B,C works fine.
Policy B - user B with scope B,C,D gives 403.
Policy C - user C with scope C,D,E gives 403.
If User B is added to Policy A it works fine and retunes combined result of scope A,B,C,D.
For User C we need to this add this user to both policy A,B and it works fine and retunes combined result of scope A,B,C,D,E.
We want this to work independently. For user B and C to work by adding them to policy B for user B and policy C for user C.
Both Policies are Positive and Both Permissions are Affirmative.
In Evaluate page it shows as expected but from Postman it gives error.
JSON from Authorization Export
{
"allowRemoteResourceManagement": false,
"policyEnforcementMode": "ENFORCING",
"resources": [
{
"name": "ResourceA",
"type": "urn:generic-rest-api:resources:employees",
"ownerManagedAccess": false,
"attributes": {},
"_id": "1b41c828-b78f-44da-84ab-e62a0b4843b5",
"uris": [
"/v1/employees/*"
],
"scopes": [
{
"name": "urn:generic-rest-api:scopes:employees:attribute:admindescription:view"
},
{
"name": "urn:generic-rest-api:scopes:employees:attribute:accessRole:view"
},
{
"name": "urn:generic-rest-api:scopes:employees:attribute:address:view"
}
]
},
{
"name": "ResourceB",
"type": "urn:generic-rest-api:resources:employees",
"ownerManagedAccess": false,
"displayName": "ResourceB",
"attributes": {},
"_id": "6237e427-55ef-4c1e-9e3d-714e5bfe31c9",
"uris": [
"/v1/employees/*"
],
"scopes": [
{
"name": "urn:generic-rest-api:scopes:employees:attribute:admindescription:view"
},
{
"name": "urn:generic-rest-api:scopes:employees:attribute:companyid:view"
},
{
"name": "urn:generic-rest-api:scopes:employees:attribute:authorizedAmount:view"
}
]
},
{
"name": "Default Resource",
"type": "urn:employee-rest-api:resources:default",
"ownerManagedAccess": false,
"attributes": {},
"_id": "fb476666-f779-4a86-8234-d49e897f6405",
"uris": [
"/*"
]
}
],
"policies": [
{
"id": "1e08f5f3-a766-416b-9448-50716dd0580b",
"name": "PolicyB",
"type": "user",
"logic": "POSITIVE",
"decisionStrategy": "UNANIMOUS",
"config": {
"users": "[\"UserB\"]"
}
},
{
"id": "8f90f109-0c7b-4caa-9620-50b7d36bd463",
"name": "Default Policy",
"description": "A policy that grants access only for users within this realm",
"type": "js",
"logic": "POSITIVE",
"decisionStrategy": "AFFIRMATIVE",
"config": {
"code": "// by default, grants any permission associated with this policy\n$evaluation.grant();\n"
}
},
{
"id": "c4ce02d8-cb2d-479f-ad22-82f092535b1b",
"name": "PolicyA",
"type": "user",
"logic": "POSITIVE",
"decisionStrategy": "UNANIMOUS",
"config": {
"users": "[\"UserA\"]"
}
},
{
"id": "29f9ae37-afa9-4a98-864f-bc9f8dd7a783",
"name": "PermissionA",
"type": "resource",
"logic": "POSITIVE",
"decisionStrategy": "AFFIRMATIVE",
"config": {
"resources": "[\"ResourceA\"]",
"applyPolicies": "[\"PolicyA\"]"
}
},
{
"id": "3b71972f-3754-464d-99b6-f5c11e5962cc",
"name": "PermissionB",
"type": "resource",
"logic": "POSITIVE",
"decisionStrategy": "AFFIRMATIVE",
"config": {
"resources": "[\"ResourceB\"]",
"applyPolicies": "[\"PolicyB\"]"
}
},
{
"id": "3f21cf9d-f0b4-4b54-a3b9-5cbc4c1f060c",
"name": "Default Permission",
"description": "A permission that applies to the default resource type",
"type": "resource",
"logic": "POSITIVE",
"decisionStrategy": "AFFIRMATIVE",
"config": {
"defaultResourceType": "urn:employee-rest-api:resources:default",
"applyPolicies": "[\"Default Policy\"]"
}
}
],
"scopes": [
{
"id": "c14170f6-0ef7-416e-bde8-c394f6f3ed13",
"name": "urn:generic-rest-api:scopes:employees:attribute:admindescription:view"
},
{
"id": "1d88b211-7961-4a2b-bfae-696566366f1f",
"name": "urn:generic-rest-api:scopes:employees:attribute:adusertype:view"
},
{
"id": "bfa6a52a-46de-4e86-8c72-4ea738752cd0",
"name": "urn:generic-rest-api:scopes:employees:attribute:accessRole:view"
},
{
"id": "f646b5af-bcc4-42a5-b135-de5d0c78ac5b",
"name": "urn:generic-rest-api:scopes:employees:attribute:address:view"
},
{
"id": "50286c2a-b0b4-423b-ac99-9b7b64bdebee",
"name": "urn:generic-rest-api:scopes:employees:attribute:authorizedAmount:view"
},
{
"id": "08140d1b-1c51-4563-96c4-4f6a628e9933",
"name": "urn:generic-rest-api:scopes:employees:attribute:companyid:view"
}
],
"decisionStrategy": "UNANIMOUS"
}

How to extract a specific part from JSON response with Java in Spring Boot?

I am trying to get the current status of a flight from a 3rd party API. I just need very few fields from the JSON. If I do it in the traditional way I would have to create many classes. And, map the json to the classes. Is there a better way of doing it. In the JSON response,I just need the information in the FlightStatuses field.
{
"request": {
"airline": {
"fsCode": "AA",
"requestedCode": "AA"
},
"flight": {
"requested": "100",
"interpreted": "100"
},
"utc": {
"requested": "false",
"interpreted": false
},
"url": "https://api.flightstats.com/flex/flightstatus/rest/v2/json/flight/status/AA/100/dep/2019/10/1?utc=false",
"nonstopOnly": {
"interpreted": false
},
"date": {
"year": "2019",
"month": "10",
"day": "1",
"interpreted": "2019-10-01"
}
},
"appendix": {
"airlines": [
{
"fs": "AA",
"iata": "AA",
"icao": "AAL",
"name": "American Airlines",
"phoneNumber": "08457-567-567",
"active": true
},
{
"fs": "AY",
"iata": "AY",
"icao": "FIN",
"name": "Finnair",
"phoneNumber": "+ 358 600 140 140",
"active": true
},
{
"fs": "IB",
"iata": "IB",
"icao": "IBE",
"name": "Iberia",
"phoneNumber": "1800 772 4642",
"active": true
},
{
"fs": "LY",
"iata": "LY",
"icao": "ELY",
"name": "El Al",
"phoneNumber": "+ 972-3-9771111",
"active": true
},
{
"fs": "BA",
"iata": "BA",
"icao": "BAW",
"name": "British Airways",
"phoneNumber": "1-800-AIRWAYS",
"active": true
},
{
"fs": "GF",
"iata": "GF",
"icao": "GFA",
"name": "Gulf Air",
"phoneNumber": "973 17 335 777",
"active": true
}
],
"airports": [
{
"fs": "LHR",
"iata": "LHR",
"icao": "EGLL",
"faa": "",
"name": "London Heathrow Airport",
"city": "London",
"cityCode": "LON",
"stateCode": "EN",
"countryCode": "GB",
"countryName": "United Kingdom",
"regionName": "Europe",
"timeZoneRegionName": "Europe/London",
"weatherZone": "",
"localTime": "2019-10-01T15:25:25.492",
"utcOffsetHours": 1.0,
"latitude": 51.469603,
"longitude": -0.453566,
"elevationFeet": 80,
"classification": 1,
"active": true,
"weatherUrl": "https://api.flightstats.com/flex/weather/rest/v1/json/all/LHR?codeType=fs",
"delayIndexUrl": "https://api.flightstats.com/flex/delayindex/rest/v1/json/airports/LHR?codeType=fs"
},
{
"fs": "JFK",
"iata": "JFK",
"icao": "KJFK",
"faa": "JFK",
"name": "John F. Kennedy International Airport",
"street1": "JFK Airport",
"city": "New York",
"cityCode": "NYC",
"stateCode": "NY",
"postalCode": "11430",
"countryCode": "US",
"countryName": "United States",
"regionName": "North America",
"timeZoneRegionName": "America/New_York",
"weatherZone": "NYZ178",
"localTime": "2019-10-01T10:25:25.493",
"utcOffsetHours": -4.0,
"latitude": 40.642335,
"longitude": -73.78817,
"elevationFeet": 13,
"classification": 1,
"active": true,
"weatherUrl": "https://api.flightstats.com/flex/weather/rest/v1/json/all/JFK?codeType=fs",
"delayIndexUrl": "https://api.flightstats.com/flex/delayindex/rest/v1/json/airports/JFK?codeType=fs"
}
],
"equipments": [
{
"iata": "77W",
"name": "Boeing 777-300ER",
"turboProp": false,
"jet": true,
"widebody": true,
"regional": false
}
]
},
"flightStatuses": [
{
"flightId": 1016157813,
"carrierFsCode": "AA",
"flightNumber": "100",
"departureAirportFsCode": "JFK",
"arrivalAirportFsCode": "LHR",
"departureDate": {
"dateUtc": "2019-10-01T22:15:00.000Z",
"dateLocal": "2019-10-01T18:15:00.000"
},
"arrivalDate": {
"dateUtc": "2019-10-02T05:20:00.000Z",
"dateLocal": "2019-10-02T06:20:00.000"
},
"status": "S",
"schedule": {
"flightType": "J",
"serviceClasses": "RFJY",
"restrictions": "",
"uplines": [],
"downlines": []
},
"operationalTimes": {
"publishedDeparture": {
"dateUtc": "2019-10-01T22:15:00.000Z",
"dateLocal": "2019-10-01T18:15:00.000"
},
"scheduledGateDeparture": {
"dateUtc": "2019-10-01T22:15:00.000Z",
"dateLocal": "2019-10-01T18:15:00.000"
},
"estimatedGateDeparture": {
"dateUtc": "2019-10-01T22:15:00.000Z",
"dateLocal": "2019-10-01T18:15:00.000"
},
"publishedArrival": {
"dateUtc": "2019-10-02T05:20:00.000Z",
"dateLocal": "2019-10-02T06:20:00.000"
},
"scheduledGateArrival": {
"dateUtc": "2019-10-02T05:20:00.000Z",
"dateLocal": "2019-10-02T06:20:00.000"
},
"estimatedGateArrival": {
"dateUtc": "2019-10-02T05:20:00.000Z",
"dateLocal": "2019-10-02T06:20:00.000"
}
},
"codeshares": [
{
"fsCode": "AY",
"flightNumber": "4012",
"relationship": "L"
},
{
"fsCode": "BA",
"flightNumber": "1511",
"relationship": "L"
},
{
"fsCode": "GF",
"flightNumber": "6654",
"relationship": "L"
},
{
"fsCode": "IB",
"flightNumber": "4218",
"relationship": "L"
},
{
"fsCode": "LY",
"flightNumber": "8051",
"relationship": "L"
}
],
"delays": {},
"flightDurations": {
"scheduledBlockMinutes": 425
},
"airportResources": {
"departureTerminal": "8",
"departureGate": "16",
"arrivalTerminal": "3"
},
"flightEquipment": {
"scheduledEquipmentIataCode": "77W",
"actualEquipmentIataCode": "77W",
"tailNumber": "N730AN"
}
}
]
}
You can parse your JSON as JsonNode.
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree("[your JSON here]");
After that get only fields, which you need. For example:
jsonNode.get("request").get("airline").get("requestedCode").asText()
Google's Gson could be used to get Json's Object, Array and other Wrapper class from Object.
Gson gson = new Gson();
JsonElement jsonElement = gson.toJsonTree(flightObject);
JsonArray jsonArray = jsonElement.getAsJsonObject().get("flightStatuses").getAsJsonArray();
System.out.println(gson.toJson(jsonArray));
You can just use an object with flightStatuses and ignore the rest essentially;
public class FlightStatusContainer {
private List<FlightStatus> flightStatuses;
// getter & setters
}
If you need only some parts of each FlightStatus object, you can ignore those fields as well in that object. For example let's say that you only need status;
public class FlightStatus {
private String status;
// getter & setters
}
and use these in your 3rd party API call (e.g. with RestTemplate);
FlightStatusContainer fsc = restTemplate.getForObject(targetUrl, FlightStatusContainer.class);
// can use fsc.getFlightStatuses(), and the rest is ignored
will get you a super simplified result;
{
"flightStatuses": [
{
"status": "S"
},
{
"status": "P"
}
]
}

How parse this nest json use gson & java? & getvalues

I want to retrieve the value that is in the following from Json 'en' 'ja''de' & make a string.xml for the android with the acquired value does it taken out doing what from such nested JSON
`{                                            
"resources": {                            
"string": {
"en": [
{
"name": "Parts",
"character": "wheel"
},
{
"name": "Box",
"character": "container"
},
{
"name": "ZentraleTeile",
"character": "engine"
},
{
"name": "Electric",
"character": "battery"
},
{
"name": "Kabel",
"character": "flatcable"
}
],
"ja": [
{
"name": "Parts",
"character": "ホイール"
},
{
"name": "Box",
"character": "コンテナ"
},
{
"name": "ZentraleTeile",
"character": "エンジン"
},
{
"name": "Electric",
"character": "バッテリー"
},
{
"name": "Kabel",
"character": "フラットケーブル"
}
],
"zh": [
{
"name": "Name",
"character": "KOM指南2"
},
{
"name": "Parts",
"character": "轮"
},
{
"name": "Box",
"character": "集装箱"
},
{
"name": "ZentraleTeile",
"character": "发动机"
},
{
"name": "Electric",
"character": "电池"
},
{
"name": "Kabel",
"character": "扁平电缆"
}
],
"de": [
{
{
"name": "Parts",
"character": "Rad"
},
{
"name": "Box",
"character": "Container"
},
{
"name": "ZentraleTeile",
"character": "Motor"
},
{
"name": "Electric",
"character": "Batterie"
},
{
"name": "Kabel",
"character": "Flachbandkabel"
}
]
}
}
}`
How can I easily do this with GSON and java?
You'll have to use the JsonDeserializer that comes with GSON, to write your custom deserializer just go to the link:
https://sites.google.com/site/gson/gson-user-guide#TOC-Writing-a-Deserializer (present in Custom JSON deserializer using Gson)
Also check the existing stack overflow response because he has an example using the GsonBuilder, because you need to register the adapter.

How to implement an autocomplete search field (suggestor) with an existing ElasticSearch index?

The ES index consists of 2 types that are implicitly mapped (default mapping). One type is "person" or an author, the 2nd type is "document".
The index has some 500k entries.
What I have to do is: implement an autocomplete (suggestions) functionality where only the fields "title", "classification" (document) and "name" (author) are relevant for the suggestions shown to the user.
Could it be done without changing the 500k docs in the index?
I found some tutorials that suggest preparing a specific mapping and also altering the documents (this I want to avoid if possible) and so on but I am new to this and I am not sure how to go about the this problem?
Below is the JSON for the index, and how the documents look:
//a Document
{
"rawsource": "Phys.Rev. D67 (2003) 084031",
"pubyear": 2003,
"citedFrom": 19,
"topics": [
{
"name": "General Relativity and Quantum Cosmology"
}
],
"cited": [
{
"ref": 0,
"id": "PN132433"
},
{
"ref": 1,
"id": "PN206900"
}
],
"id": "PN120001",
"collection": "PN",
"source": "Phys Rev D",
"classification": "Physics",
"title": "Observables in causal set cosmology",
"url": "http://arxiv.org/abs/gr-qc/0210061",
"authors": [
{
"name": "Brightwell, Graham"
},
{
"name": "Dowker, H. Fay"
},
{
"name": "Garcia, Raquel S."
},
{
"name": "Henson, Joe"
},
{
"name": "Sorkin, Rafael D."
}
]
}
//a Person (author)
{
"name": "Terasawa, M.",
"documents": [
{
"citedFrom": 0,
"id": "PN039187"
}
],
"coAuthors": [
{
"name": "Famiano, M. A.",
"count": "1"
},
{
"name": "Boyd, R. N.",
"count": "1"
}
],
"topics": [
{
"name": "Astrophysics",
"count": "1"
}
]
}
//the mapping (implicit/default)
{
"dlsnew": {
"aliases": {
},
"mappings": {
"person": {
"properties": {
"coAuthors": {
"properties": {
"count": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"documents": {
"properties": {
"citedFrom": {
"type": "long"
},
"id": {
"type": "string"
}
}
},
"name": {
"type": "string"
},
"referenced": {
"properties": {
"count": {
"type": "string"
},
"id": {
"type": "string"
}
}
},
"topics": {
"properties": {
"count": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
},
"document": {
"properties": {
"abstract": {
"type": "string"
},
"authors": {
"properties": {
"name": {
"type": "string"
}
}
},
"cited": {
"properties": {
"id": {
"type": "string"
},
"ref": {
"type": "long"
}
}
},
"citedFrom": {
"type": "long"
},
"classification": {
"type": "string"
},
"collection": {
"type": "string"
},
"id": {
"type": "string"
},
"pubyear": {
"type": "long"
},
"rawsource": {
"type": "string"
},
"source": {
"type": "string"
},
"title": {
"type": "string"
},
"topics": {
"properties": {
"name": {
"type": "string"
}
}
},
"url": {
"type": "string"
}
}
}
},
"settings": {
"index": {
"creation_date": "1454247029258",
"number_of_shards": "5",
"uuid": "k_CyQaxwSAaae67wW98HyQ",
"version": {
"created": "1050299"
},
"number_of_replicas": "1"
}
},
"warmers": {
}
}
}
The implementation is to be done using JAVA and the Vaadin Framework (this is not relevant at this point, but examples in Java/Vaadin will be most welcomed).
Thanks.
So, I think I solved my problem on the Elasticsearch side or at least to a good enough extend for me and the task at hand. I followed this ruby example.
I had to re-index all documents to accommodate the new settings for my index and to change my mapping explicitly.
They key is in defining proper analyzers and an edgeNGram filter in this case, like so:
"settings": {
"index": {
"analysis": {
"filter": {
"def_ngram_filter": {
"min_gram": "1",
"side": "front",
"type": "edgeNGram",
"max_gram": "16"
}
},
"analyzer": {
"def_search_analyzer": {
"filter": [
"lowercase",
"asciifolding"
],
"type": "custom",
"tokenizer": "def_tokenizer"
},
"def_ngram_analyzer": {
"filter": [
"lowercase",
"asciifolding",
"def_ngram_filter"
],
"type": "custom",
"tokenizer": "def_tokenizer"
},
"def_shingle_analyzer": {
"filter": [
"shingle",
"lowercase",
"asciifolding"
],
"type": "custom",
"tokenizer": "def_tokenizer"
},
"def_default_analyzer": {
"filter": [
"lowercase",
"asciifolding"
],
"type": "custom",
"tokenizer": "def_tokenizer"
}
},
"tokenizer": {
"def_tokenizer": {
"type": "whitespace"
}
}
}
}
}
and the use these in the mapping for the fields to be searched, like so:
"mappings": {
"person": {
"properties": {
"coAuthors": {
"properties": {
"count": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"documents": {
"properties": {
"citedFrom": {
"type": "long"
},
"id": {
"type": "string"
}
}
},
"name": {
"type": "string",
"analyzer": "def_default_analyzer",
"fields": {
"ngrams": {
"type": "string",
"index_analyzer": "def_ngram_analyzer",
"search_analyzer": "def_search_analyzer"
},
"shingles": {
"type": "string",
"analyzer": "def_shingle_analyzer"
},
"stemmed": {
"type": "string",
"analyzer": "def_snowball_analyzer"
}
}
},
"referenced": {
"properties": {
"count": {
"type": "string"
},
"id": {
"type": "string"
}
}
},
"topics": {
"properties": {
"count": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
},
"document": {
"properties": {
"abstract": {
"type": "string"
},
"authors": {
"properties": {
"name": {
"type": "string",
"analyzer": "def_default_analyzer",
"fields": {
"ngrams": {
"type": "string",
"index_analyzer": "def_ngram_analyzer",
"search_analyzer": "def_search_analyzer"
},
"shingles": {
"type": "string",
"analyzer": "def_shingle_analyzer"
},
"stemmed": {
"type": "string",
"analyzer": "def_snowball_analyzer"
}
}
}
}
},
"cited": {
"properties": {
"id": {
"type": "string"
},
"ref": {
"type": "long"
}
}
},
"citedFrom": {
"type": "long"
},
"classification": {
"type": "string"
},
"collection": {
"type": "string"
},
"id": {
"type": "string"
},
"pubyear": {
"type": "long"
},
"rawsource": {
"type": "string"
},
"source": {
"type": "string"
},
"title": {
"type": "string",
"analyzer": "def_default_analyzer",
"fields": {
"ngrams": {
"type": "string",
"index_analyzer": "def_ngram_analyzer",
"search_analyzer": "def_search_analyzer"
},
"shingles": {
"type": "string",
"analyzer": "def_shingle_analyzer"
},
"stemmed": {
"type": "string",
"analyzer": "def_snowball_analyzer"
}
}
},
"topics": {
"properties": {
"name": {
"type": "string",
"analyzer": "def_default_analyzer",
"fields": {
"ngrams": {
"type": "string",
"index_analyzer": "def_ngram_analyzer",
"search_analyzer": "def_search_analyzer"
},
"shingles": {
"type": "string",
"analyzer": "def_shingle_analyzer"
},
"stemmed": {
"type": "string",
"analyzer": "def_snowball_analyzer"
}
}
}
}
},
"url": {
"type": "string"
}
}
}
}
then querying the index with the following works as expected:
curl -XGET "http://localhost:9200/_search " -d'
{
"size": 5,
"query": {
"multi_match": {
"query": "physics",
"type": "most_fields",
"fields": [
"document.title^10",
"document.title.shingles^2",
"document.title.ngrams",
"person.name^10",
"person.name.shingles^2",
"person.name.ngrams",
"document.topics.name^10",
"document.topics.name.shingles^2",
"document.topics.name.ngrams"
],
"operator": "and"
}
}
}'
Hope this will help someone, it is probably not the best example as I am a complete noob to this, but it worked for me.
There exist different Autocomplete components for Vaadin.
Have a look at this link.
Depending on which Add-On you choose, the databinding is done differently, but you have to "connect" it to your index.

Issue with json Content type for DeepInsert

I'm trying deepinsert with Json on the service,http://services.odata.org/(S(egpbfjhhvili4slwaq1p2lvt))/V2/OData/OData.svc/Categories with body--
{
"d" : {
"__metadata": {
"uri":"http://services.odata.org/(S(egpbfjhhvili4slwaq1p2lvt))/V2/odata/OData.svc/Categories(0)", "type": "ODataDemo.Category"
}, "ID": 97, "Name": "Food", "Products": [
{
"__metadata": {
"uri":"http://services.odata.org/(S(egpbfjhhvili4slwaq1p2lvt))/V2/odata/OData.svc/Products( 0)", "type": "ODataDemo.Product"
}, "ID": 97, "Name": "Bread", "Description": "Whole grain bread", "ReleaseDate": "\/Date(694224000000)\/", "DiscontinuedDate": null, "Rating": 4, "Price": "2.5", "Category": {
"__deferred": {
"uri":"http://services.odata.org/(S(egpbfjhhvili4slwaq1p2lvt))/V2/odata/OData.svc/Products(0)/Category"
}
}, "Supplier": {
"__deferred": {
"uri":"http://services.odata.org/(S(egpbfjhhvili4slwaq1p2lvt))/V2/odata/OData.svc/Products(0)/Supplier"
}
}
}
]
}
}
and I get the 400 Bad request with error description:
{
error: {
code: ""
message: {
lang: "en-US"
value: "Error processing request stream. The property name 'd' specified for type 'ODataDemo.Category' is not valid."
}-
}-
}
Can someone help me figure out what I'm doing wrong here?
There is no need to append "d" in the body of post request.
Remove the "d" and send the body like this:
{
"__metadata": {
"uri":"http://services.odata.org/(S(egpbfjhhvili4slwaq1p2lvt))/V2/odata/OData.svc/Categories(0)", "type": "ODataDemo.Category"
}, "ID": 97, "Name": "Food", "Products": [
{
"__metadata": {
"uri":"http://services.odata.org/(S(egpbfjhhvili4slwaq1p2lvt))/V2/odata/OData.svc/Products( 0)", "type": "ODataDemo.Product"
}, "ID": 97, "Name": "Bread", "Description": "Whole grain bread", "ReleaseDate": "\/Date(694224000000)\/", "DiscontinuedDate": null, "Rating": 4, "Price": "2.5", "Category": {
"__deferred": {
"uri":"http://services.odata.org/(S(egpbfjhhvili4slwaq1p2lvt))/V2/odata/OData.svc/Products(0)/Category"
}
}, "Supplier": {
"__deferred": {
"uri":"http://services.odata.org/(S(egpbfjhhvili4slwaq1p2lvt))/V2/odata/OData.svc/Products(0)/Supplier"
}
}
}
]
}

Categories

Resources